Subject: bug#8498: 23.3; mail-abbrev-next-line expands abbrevs when it should not

From: "David J. Biesack" <[email-masked]>
Date: Thu, 14 Apr 2011 09:30:58 -0400

In rmail, reply to a message. In my case, the From: line in the
*mail to...** buffer is formatted as:

From: [email-masked] (David J. Biesack)

(In my case, mail-from-style is 'parens ; user-full-name is "David J. Biesack" )

Position point at the end of the From: line formatted as above.
Press C-n which is bound to mail-abbrev-next-line 

If the text before the close parentheses ("Biesack" in this case) is also a
defined mail abbrev (i.e. in my ~/.mailrc file) such as 

  alias biesack [email-masked]

then mail-abbrev-next-line will expand that name, yielding:

From: [email-masked] (David J. [email-masked])

The following change to the function from mailabbrev.el fixes this, but I've not
tested this in all possible scenarios

(defun mail-abbrev-next-line (&optional arg)
  "Expand a mail abbrev before point, then move vertically down ARG lines.
This only expands an abbrev (if one is present) if called with
point at the end of a line, or on whitespace before the end of a line.

In terms of line motion, this behaves like `next-line', which see."
  (interactive "p")
  (if (and (looking-at "[ \t]*\n") 
           (> (current-column) 0)
           (/= (char-after (- (point) 1)) ?\)) )
      (expand-abbrev))

  (setq this-command 'next-line)
  (with-no-warnings (next-line arg)))

This updated function works for example if .mailrc contains 

alias gnu [email-masked]

and you use mail-abbrev-next-line at the end of the following lines:

To: gnu 
To: [email-masked], gnu
To: [email-masked],gnu
To: [email-masked];gnu
To: [email-masked], gnu

I did not alter the function to check the current header;
i.e. it does not make sense to expand abbrevs if the header
is From:  . I did note that abbrev expansion does not happen
on Subject: and In-Reply-To: header lines but I don't see
where that is done. If possible, From: should be added
to that list. But the fix is still needed in case a
To: or Cc: or Bcc: line uses the paren syntax.

Also, message.el contains

(if (featurep 'xemacs)
    (require 'mail-abbrevs)
  (require 'mailabbrev))

but I did not visit mail-abbrevs to see if it has the same problem;
I do not use xemacs

thanks

In GNU Emacs 23.3.1 (x86_64-unknown-linux-gnu)
 of 2011-03-28 on djb
Windowing system distributor `The X.Org Foundation', version 11.0.10900000
configured using `configure  '--with-xpm=no' '--with-jpeg=no' '--with-png=no' '--with-gif=no' '--with-tiff=no''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  display-time-mode: t
  delete-selection-mode: t
  pc-selection-mode: t
  show-paren-mode: t
  iswitchb-mode: t
  nxhtml-menu-mode: t
  nxhtml-tag-do-also: t
  popcmp-group-alternatives: t
  popcmp-short-help-beside-alts: t
  mlinks-active-links: t
  rngalt-minimal-validation-header: t
  rngalt-display-validation-header: t
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t
  hs-minor-mode: t

Recent input:
- c h a r s - C-p C-p C-n M-b M-b C-SPC C-n C-e C-w 
o r SPC ( e <backspace> c h a r - a t SPC ( - SPC ( 
p o i n t SPC <backspace> ) SPC 1 ) M-b M-b M-b M-b 
C-h f <return> e <backspace> = SPC ( C-e ) <M-return> 
q C-h f c h a r - a SPC SPC <return> C-p M-f M-f M-f 
<backspace> f e r C-e SPC ; = <backspace> <backspace> 
? ) C-SPC C-M-b w C-e C-/ C-SPC C-/ C-/ C-/ C-SPC C-SPC 
C-M-b M-w C-e C-j C-y C-b C-e C-p C-b \ C-e ) C-n <backspace> 
\ > <backspace> <backspace> > _ ) <backspace> <backspace> 
) ) ) C-p C-p C-p C-p C-e C-n C-e C-n C-SPC C-p C-e 
C-SPC C-SPC C-M-b C-w C-n C-n C-n C-e C-j C-y ) C-x 
o C-x k SPC C-p C-p C-p C-x o C-p C-p <escape> E C-x 
o C-x b * m a <return> C-p C-n C-n C-x o C-h f <return> 
C-f C-f C-f C-f t <down> <left> t <escape> E C-x o 
C-n C-e C-n C-/ C-p C-n C-n C-p C-p C-n C-e C-x p <escape> 
D C-e C-x o C-n SPC SPC SPC SPC SPC SPC SPC SPC SPC 
SPC SPC SPC SPC SPC SPC SPC q <down-mouse-1> <mouse-1> 
/ <backspace> <backspace> <backspace> <backspace> <backspace> 
/ C-h f <return> C-e <backspace> C-n M-m C-f / C-e 
<backspace> ) TAB q <backspace> C-p C-p C-n <backspace> 
) ) C-n TAB C-e <backspace> <escape> E C-x o C-x , 
C-n C-p C-p C-n C-n C-p C-h c C-p C-p C-n C-n C-p C-b 
C-p C-x o <down-mouse-1> <mouse-1> <down-mouse-1> <mouse-1> 
<down-mouse-1> <mouse-1> M-x r e p o r t - e m SPC 
<return>

Recent messages:

Result: 107 (#o153, #x6b, ?k)

Result: 41 (#o51, #x29, ?\))

Result: t
Back to top level.
Auto-saving...done
mail-abbrev-next-line
C-p runs the command previous-line

Load-path shadows:
/u/sasdjb/emacs/nxhtml/web-vcs hides /u/sasdjb/emacs/web-vcs
/u/sasdjb/emacs/nxhtml/nxhtml-web-vcs hides /u/sasdjb/emacs/nxhtml-web-vcs
/u/sasdjb/emacs/indent hides /home/sasdjb/linux/emacs/lisp/indent
/u/sasdjb/emacs/whitespace hides /home/sasdjb/linux/emacs/lisp/whitespace
/u/sasdjb/emacs/ls-lisp hides /home/sasdjb/linux/emacs/lisp/ls-lisp
/u/sasdjb/emacs/bs hides /home/sasdjb/linux/emacs/lisp/bs
/u/sasdjb/emacs/xml hides /home/sasdjb/linux/emacs/lisp/xml
/u/sasdjb/emacs/uniquify hides /home/sasdjb/linux/emacs/lisp/uniquify
/u/sasdjb/emacs/align hides /home/sasdjb/linux/emacs/lisp/align
/u/sasdjb/emacs/wdired hides /home/sasdjb/linux/emacs/lisp/wdired
/u/sasdjb/emacs/cmuscheme hides /home/sasdjb/linux/emacs/lisp/cmuscheme
/u/sasdjb/emacs/autoinsert hides /home/sasdjb/linux/emacs/lisp/autoinsert
/u/sasdjb/emacs/ibuffer hides /home/sasdjb/linux/emacs/lisp/ibuffer
/u/sasdjb/emacs/url/url-handlers hides /home/sasdjb/linux/emacs/lisp/url/url-handlers
/u/sasdjb/emacs/url/url-mailto hides /home/sasdjb/linux/emacs/lisp/url/url-mailto
/u/sasdjb/emacs/url/url-misc hides /home/sasdjb/linux/emacs/lisp/url/url-misc
/u/sasdjb/emacs/url/url-file hides /home/sasdjb/linux/emacs/lisp/url/url-file
/u/sasdjb/emacs/url/url-cache hides /home/sasdjb/linux/emacs/lisp/url/url-cache
/u/sasdjb/emacs/url/url-http hides /home/sasdjb/linux/emacs/lisp/url/url-http
/u/sasdjb/emacs/url/url-cid hides /home/sasdjb/linux/emacs/lisp/url/url-cid
/u/sasdjb/emacs/url/url-methods hides /home/sasdjb/linux/emacs/lisp/url/url-methods
/u/sasdjb/emacs/url/url-about hides /home/sasdjb/linux/emacs/lisp/url/url-about
/u/sasdjb/emacs/url/url-nfs hides /home/sasdjb/linux/emacs/lisp/url/url-nfs
/u/sasdjb/emacs/url/url-gw hides /home/sasdjb/linux/emacs/lisp/url/url-gw
/u/sasdjb/emacs/url/url-parse hides /home/sasdjb/linux/emacs/lisp/url/url-parse
/u/sasdjb/emacs/url/url-ftp hides /home/sasdjb/linux/emacs/lisp/url/url-ftp
/u/sasdjb/emacs/url/url-ns hides /home/sasdjb/linux/emacs/lisp/url/url-ns
/u/sasdjb/emacs/url/url-cookie hides /home/sasdjb/linux/emacs/lisp/url/url-cookie
/u/sasdjb/emacs/url/url-util hides /home/sasdjb/linux/emacs/lisp/url/url-util
/u/sasdjb/emacs/url/url-proxy hides /home/sasdjb/linux/emacs/lisp/url/url-proxy
/u/sasdjb/emacs/url/url-privacy hides /home/sasdjb/linux/emacs/lisp/url/url-privacy
/u/sasdjb/emacs/url/url-ldap hides /home/sasdjb/linux/emacs/lisp/url/url-ldap
/u/sasdjb/emacs/url/url-auth hides /home/sasdjb/linux/emacs/lisp/url/url-auth
/u/sasdjb/emacs/url/url-dired hides /home/sasdjb/linux/emacs/lisp/url/url-dired
/u/sasdjb/emacs/url/url-history hides /home/sasdjb/linux/emacs/lisp/url/url-history
/u/sasdjb/emacs/url/url-irc hides /home/sasdjb/linux/emacs/lisp/url/url-irc
/u/sasdjb/emacs/url/url-vars hides /home/sasdjb/linux/emacs/lisp/url/url-vars
/u/sasdjb/emacs/url/url-expand hides /home/sasdjb/linux/emacs/lisp/url/url-expand
/u/sasdjb/emacs/url/url hides /home/sasdjb/linux/emacs/lisp/url/url
/u/sasdjb/emacs/url/url-imap hides /home/sasdjb/linux/emacs/lisp/url/url-imap
/u/sasdjb/emacs/url/url-dav hides /home/sasdjb/linux/emacs/lisp/url/url-dav
/u/sasdjb/emacs/url/url-news hides /home/sasdjb/linux/emacs/lisp/url/url-news
/u/sasdjb/emacs/table hides /home/sasdjb/linux/emacs/lisp/textmodes/table
/u/sasdjb/emacs/icon hides /home/sasdjb/linux/emacs/lisp/progmodes/icon
/u/sasdjb/emacs/hideshow hides /home/sasdjb/linux/emacs/lisp/progmodes/hideshow
/u/sasdjb/emacs/cpp hides /home/sasdjb/linux/emacs/lisp/progmodes/cpp
/u/sasdjb/emacs/glasses hides /home/sasdjb/linux/emacs/lisp/progmodes/glasses
/u/sasdjb/emacs/xscheme hides /home/sasdjb/linux/emacs/lisp/progmodes/xscheme
/u/sasdjb/emacs/sh-script hides /home/sasdjb/linux/emacs/lisp/progmodes/sh-script
/u/sasdjb/emacs/zone hides /home/sasdjb/linux/emacs/lisp/play/zone
/u/sasdjb/emacs/solitaire hides /home/sasdjb/linux/emacs/lisp/play/solitaire
/u/sasdjb/emacs/quickurl hides /home/sasdjb/linux/emacs/lisp/net/quickurl
/u/sasdjb/emacs/metamail hides /home/sasdjb/linux/emacs/lisp/mail/metamail
/u/sasdjb/emacs/elp hides /home/sasdjb/linux/emacs/lisp/emacs-lisp/elp
/u/sasdjb/emacs/trace hides /home/sasdjb/linux/emacs/lisp/emacs-lisp/trace
/u/sasdjb/emacs/re-builder hides /home/sasdjb/linux/emacs/lisp/emacs-lisp/re-builder
/u/sasdjb/emacs/eldoc hides /home/sasdjb/linux/emacs/lisp/emacs-lisp/eldoc

Features:
(shadow emacsbug dired-aux cl-specs parse-time vc-cvs cperl-mode script-mode rmailout align ef man ddtags rmailedit dabbrev mailalias gnus-msg gnus-art mm-uu mml2015 epg-config mm-view smime dig gnus-sum nnoo gnus-group gnus-undo nnmail mail-source gnus-start gnus-spec gnus-int gnus-range gnus-win gnus gnus-ems mail-extr sort par-align debug edebug rmailsum rect make-mode ansi-color filemenu skeleton sh-script executable tabify browse-region-as-html bg goto-addr rmail-mode-hooks message-mode-hooks ascii-conversion smtpmail mailto ph quoted-printable etach whitespace rmailmm message ecomplete rfc822 mml mml-sec mailabbrev nnheader gmm-utils mailheader canlock sha1 hex-util hashcash rmail mail-utils multi-isearch tramp-imap assoc tramp-gw tramp-fish tramp-smb tramp-cache tramp-ftp tramp-cmds tramp auth-source password-cache format-spec tramp-compat trampver add-hook shell color-themes color-theme edmacro kmacro sendmail reporter color-theme-autoloads time server gnus-dired my-keys resizing thing mosaic-client edit-server password-keeper-mode sensitive-mode password-generator ps-ccrypt andersl-java-font-lock delsel pc-select complete paren iswitchb msb javadecomp autobrowse last-mod quickurl browse-url thingatpt disp-table nxhtml-autostart nxhtml-autoload moz cc-cmds majmodpri nxhtml-menu udev-rinari udev-ecb udev flymake-js flymake css-color nxhtml-mode html-quote tidy-xhtml ediff-merg ediff-diff ediff-wind ediff-help ediff-util ediff-mult ediff-init ediff html-imenu imenu loadhist popcmp xhtml-help mlinks url-expand url-util url-methods html-toc xml fupd html-pagetoc foldit appmenu-fold appmenu mumamo sgml-mode rngalt rng-nxml nxml-mode nxml-outln nxml-rap nxml-glyph rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns nxml-util nxml-enc xmltok desktop cc-engine cc-vars cc-defs help-mode view flyspell ispell fold-dwim hideshow html-upl html-site derived url-parse url-vars ourcomments-util uniquify recentf tree-widget org byte-opt warnings org-footnote org-src org-list org-faces org-compat org-macs noutline outline ido bookmark pp apropos grep ffip compile comint ring gimpedit dired regexp-opt cl cl-19 web-vcs bytecomp byte-compile rx mm-decode gnus-util netrc mm-bodies mm-encode mailcap mail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums mm-util time-date mail-prsvr cus-edit easymenu cus-start cus-load wid-edit web-autoload nxhtml-base easy-mmode advice help-fns advice-preload tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar mldrag mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev loaddefs button minibuffer faces cus-face files text-properties overlay md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process x multi-tty emacs)

-- 
David J. Biesack, SAS
SAS Campus Dr. Cary, NC 27513
www.sas.com    (919) 531-7771