Skip to main content


elisp
God, my tab completion function is a hacky mess:
(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.

in reply to Jonathan Lamothe

elisp

@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. ;)

in reply to Jonathan Lamothe

elisp

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.

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.