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

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

abbrevs and case


From: Luc Teirlinck
Subject: abbrevs and case
Date: Thu, 26 Apr 2001 22:27:30 -0500 (CDT)

This bug report will be sent to the Free Software Foundation,
 not to your local site managers!!
Please write in English, because the Emacs maintainers do not have
translators to read other languages for them.

In GNU Emacs 20.7.1 (sparc-sun-solaris2.8, X toolkit)
 of Thu Apr 12 2001 on eel
configured using `configure  --prefix=/home/teirllm/emacshome'

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:

Concerning abbrevs:
There is a big difference in philosophy between the basic functions,
which are completely case-sensitive, and the user-level functions,
which down-case all abbrevs and then adapt the case of the expansion to
the case of the abbrev typed in by the user.

Some problems resulting from this in Emacs20.6 -q:

Define foo to expand to something.
Put the region around the following line:

Foo foo FOO

Then M-x expand-region-abbrevs will offer to expand foo, but not Foo
nor FOO.

Try to redefine foo using C-x a g and C-x a i g.
In both cases you get warned that foo already has a meaning,
This does not happen if you used Foo or FOO as the abbrev symbol, even 
though C-x a g and C-x a i g both down-case the symbol anyway.

The documentation string of `abbrev-expansion' is misleading.
(This is probably the cause of the above problems.)
It says:

Return the string that ABBREV expands into in the current buffer.
Optionally specify an abbrev table as second arg;
then ABBREV is looked up in that table only.

This is not what it does:
If foo expands to "find outer otter",
then Foo expands to: "Find outer otter" in the buffer.
However, abbrev-expansion thinks that it is not a valid abbrev,because
only foo is.  Hence, it returns nil.

I do not know what the best solution to the problem is.

One is to rewrite `abbrev-expansion' to do what it says it does.
One probably then would have to check whether that does not create any
problems in other parts of Emacs.

Another solution is to rewrite the documentation string of
`abbrev-expansion' (such a rewrite is NOT included in the context-diff
below) and apply the following diff to abbrev.el:

cd ~/
diff -c /home/teirllm/abbrev.old.el /home/teirllm/abbrev.new.el
*** /home/teirllm/abbrev.old.el Thu Apr  8 11:18:58 1999
--- /home/teirllm/abbrev.new.el Thu Apr 26 21:40:41 2001
***************
*** 231,245 ****
                     (save-excursion (forward-word (- arg)) (point))))))
        name)
      (setq name
!         (read-string (format (if exp "%s abbrev for \"%s\": "
!                                "Undefine %s abbrev: ")
!                              type exp)))
      (set-text-properties 0 (length name) nil name)
      (if (or (null exp)
            (not (abbrev-expansion name table))
            (y-or-n-p (format "%s expands to \"%s\"; redefine? "
                              name (abbrev-expansion name table))))
!       (define-abbrev table (downcase name) exp))))
        
  (defun inverse-add-mode-abbrev (arg)
    "Define last word before point as a mode-specific abbrev.
--- 231,246 ----
                     (save-excursion (forward-word (- arg)) (point))))))
        name)
      (setq name
!         (downcase
!          (read-string (format (if exp "%s abbrev for \"%s\": "
!                                 "Undefine %s abbrev: ")
!                               type exp))))
      (set-text-properties 0 (length name) nil name)
      (if (or (null exp)
            (not (abbrev-expansion name table))
            (y-or-n-p (format "%s expands to \"%s\"; redefine? "
                              name (abbrev-expansion name table))))
!       (define-abbrev table name exp))))
        
  (defun inverse-add-mode-abbrev (arg)
    "Define last word before point as a mode-specific abbrev.
***************
*** 265,273 ****
  (defun inverse-add-abbrev (table type arg)
    (let (name nameloc exp)
      (save-excursion
!      (forward-word (- arg))
!      (setq name (buffer-substring (point) (progn (forward-word 1)
!                                              (setq nameloc (point))))))
      (set-text-properties 0 (length name) nil name)
      (setq exp (read-string (format "%s expansion for \"%s\": "
                                   type name) nil nil nil t))
--- 266,276 ----
  (defun inverse-add-abbrev (table type arg)
    (let (name nameloc exp)
      (save-excursion
!       (forward-word (- arg))
!       (setq name (downcase
!                 (buffer-substring (point)
!                                   (progn (forward-word 1)
!                                          (setq nameloc (point)))))))
      (set-text-properties 0 (length name) nil name)
      (setq exp (read-string (format "%s expansion for \"%s\": "
                                   type name) nil nil nil t))
***************
*** 275,284 ****
            (y-or-n-p (format "%s expands to \"%s\"; redefine? "
                              name (abbrev-expansion name table))))
        (progn
!        (define-abbrev table (downcase name) exp)
!        (save-excursion
!         (goto-char nameloc)
!         (expand-abbrev))))))
  
  (defun abbrev-prefix-mark (&optional arg)
    "Mark current point as the beginning of an abbrev.
--- 278,287 ----
            (y-or-n-p (format "%s expands to \"%s\"; redefine? "
                              name (abbrev-expansion name table))))
        (progn
!         (define-abbrev table (downcase name) exp)
!         (save-excursion
!           (goto-char nameloc)
!           (expand-abbrev))))))
  
  (defun abbrev-prefix-mark (&optional arg)
    "Mark current point as the beginning of an abbrev.
***************
*** 305,314 ****
                  (progn (forward-word 1)
                         (<= (setq pnt (point)) (- (point-max) lim))))
        (if (abbrev-expansion
!            (setq string
!                  (buffer-substring
!                   (save-excursion (forward-word -1) (point))
!                   pnt)))
            (if (or noquery (y-or-n-p (format "Expand `%s'? " string)))
                (expand-abbrev)))))))
  
--- 308,318 ----
                  (progn (forward-word 1)
                         (<= (setq pnt (point)) (- (point-max) lim))))
        (if (abbrev-expansion
!            (downcase
!             (setq string
!                   (buffer-substring
!                    (save-excursion (forward-word -1) (point))
!                    pnt))))
            (if (or noquery (y-or-n-p (format "Expand `%s'? " string)))
                (expand-abbrev)))))))
  

Diff finished at Thu Apr 26 21:45:09

 

Recent input:
down down down down down down down down down down down 
down down down down down down down down down down down 
down down down down down down down up up up up up down 
down down down down down down down down down down down 
down down down down down down down down down down down 
down down down down down down down down down down down 
down down down C-x d return M-x r e p - e m C-g C-x 
r - e - b C-/ M-x r - e b backspace - b backspace b 
return

Recent messages:
Mark set
Directory has changed on disk; type g to update Dired
Mark set
Fontifying *diff*...
Fontifying *diff*... (regexps...........................)
Wrote /home/teirllm/diff3
Beginning of buffer [10 times]
Directory has changed on disk; type g to update Dired
Quit
Undo!



reply via email to

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