God, my tab completion function is a hacky mess:
#emacs #lisp #moo #mud #LambdaMOO
(defun lambdamoo-tab-complete ()
"Complete user input using text from the buffer"
(interactive)
(when (memq (char-before) '(? ?\r ?\n ?\t ?\v))
(user-error "Point must follow non-whitespace character"))
(let (replace-start
(replace-end (point))
replace-text found-pos found-text)
(save-excursion
(backward-word)
(setq replace-start (point)
replace-text (buffer-substring replace-start replace-end))
(when (or (null lambdamoo--search-text)
(not (string-prefix-p lambdamoo--search-text replace-text t)))
(setq-local lambdamoo--search-text replace-text)
(set-marker lambdamoo--found-point (point)))
(goto-char lambdamoo--found-point)
(unless
(setq found-pos
(re-search-backward
(concat "\\b" (regexp-quote lambdamoo--search-text))
(point-min) t))
(setq-local lambdamoo--found-point (make-marker))
(user-error "No match found"))
(set-marker lambdamoo--found-point found-pos)
(forward-word)
(setq found-text (buffer-substring found-pos (point))))
(delete-region replace-start replace-end)
(insert found-text)))#emacs #lisp #moo #mud #LambdaMOO
Lens reshared this.
Omar Antolín
in reply to Jonathan Lamothe • • •Jonathan Lamothe
in reply to Omar Antolín • •Jonathan Lamothe
in reply to Jonathan Lamothe • •@Omar Antolín Actually, looking more closely at it, it might just do the trick.
I love it when I spend hours re-writing code that essentially already exists. ;)
Jonathan Lamothe
in reply to Jonathan Lamothe • •In the end, I wound up just binding tab to
dabbrev-expand. 🙃It might seem like I wasted a bunch of time writing that, but at least I learned a bunch along the way.