emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why on earth is abbrev baked into the C code?


From: Daniel Colascione
Subject: Re: Why on earth is abbrev baked into the C code?
Date: Tue, 1 Mar 2011 13:08:55 -0800

;; This hack works for me, but there must be an easier, safer way.

(defun qtmstr-expand-abbrev-wrapper (orig-func &rest args)
  (if (and qtmstr-abbrev-mode
           (eq this-command 'self-insert-command)
           (not executing-kbd-macro)
           (not noninteractive)
           (not (window-minibuffer-p (selected-window)))
           (characterp last-command-event))

      ;; Our own implementation of expand-abbrev
      (destructuring-bind (&optional sym name wordstart wordend)
          (abbrev--before-point)

        (when sym
          (let ((value sym))
            ;; Now sym is the abbrev symbol.
            (setq last-abbrev-text name)
            (setq last-abbrev sym)
            (setq last-abbrev-location wordstart)

            ;; Do what the self-insert-command would normally do
            (insert-char last-command-event 1 t)
            (undo-boundary)
            (delete-char -1)

            ;; If this abbrev has an expansion, delete the abbrev
            ;; and insert the expansion.
            (abbrev-insert sym name wordstart wordend))))

    ;; Otherwise, let the original expand-abbrev do its thing
    (apply orig-func args)))

(add-hook 'abbrev-expand-functions #'qtmstr-expand-abbrev-wrapper)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]