emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: abbrev.c bug?


From: Luc Teirlinck
Subject: Re: abbrev.c bug?
Date: Mon, 26 Jul 2004 09:04:31 -0500 (CDT)

Katsumi Yamaoka wrote:

   2004-07-24  Richard M. Stallman  <address@hidden>
   [...]
           * abbrev.c (Fexpand_abbrev): Run Qpre_abbrev_expand_hook
           only when a real abbrev is present.

   How do I make `a real abbrev'?  Or is it a bug?

I now believe I understand the reason for that change.  There was a
bug in the example for `pre-abbrev-expand-hook' in the Elisp manual.

I believe the above change should be reverted.  Instead the bug in
the Elisp manual example should be fixed.  Or maybe the example should
just be deleted.  It is very untypical of real uses of
`pre-abbrev-expand-hook' and what it does is not really useful.
Abbrevs are a convenience feature and asking for confirmation ruins
that completely.  It does not seem to make sense, especially since
undoing the expansion is trivial and more convenient than answering a
minibuffer question.

If one wants to keep the example and fix the bug, the the following
seems to work (after reverting the above change):

(defun query-if-not-space ()
  (when (abbrev-symbol
         (buffer-substring
          (save-excursion (skip-syntax-backward "w") (point)) (point)))
    (if (/= ?\s  last-command-char)
        (if (not (y-or-n-p "Do you want to expand this abbrev? "))
            (error "Not expanding this abbrev")))))

When a function in `pre-abbrev-expand-hook' only needs to run if a
real abbrev is present, it should check whether a real abbrev is
present.  Of course, such a function should run last in the hook.
Indeed, other functions in the hook may want to change the local
abbrev-table and the syntax table and then `abbrev-symbol' and
`skip-syntax-backward' should use the modified values.  That
contradicts the advice in `(elisp)Hooks':

     It is best to design your hook functions so that the order in
     which they are executed does not matter.  Any dependence on the
     order is "asking for trouble".  However, the order is
     predictable: normally, FUNCTION goes at the front of the hook
     list, so it will be executed first (barring another `add-hook'
     call).  If the optional argument APPEND is non-`nil', the new
     hook function goes at the end of the hook list and will be
     executed last.

I do not know what to do about that.  Maybe `expand-abbrev' needs to
run two hooks.  But again, `query-if-not-space' is untypical of real
applications of `pre-abbrev-expand-hook', whose main purpose is to
allow to change what is considered an abbrev and which abbrev table
should be used. 

Sincerely,

Luc.






reply via email to

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