Subject: Re: bug#64108: hippie-expand's try-expand-all-abbrevs nil has trouble expanding abbrevs given as list(aka. expand.el snipets)

From: Yilkal Argaw Workneh <[email-masked]>
Date: Wed, 16 Apr 2025 02:38:52 +0000

On 6/16/23 4:25 PM, Eli Zaretskii wrote:
>> From: Yilkal Argaw <[email-masked]>
>> Date: Fri, 16 Jun 2023 17:24:15 +0300
>>
>> When trying to use hippie-expand to expand a simple expand.el snippet causes a bug about lists not
>> being acceptable.
>>
>> To recreate the bug use the following init.el and try to expand def using hippie expand
>> ;;init.el
>> (defconst elisp-expand-list
>>    '(("def" "(defun ()\n ) " (8 9 11 12)))
>>    "Expansions for elisp mode")
>> (add-hook 'emacs-lisp-mode-hook
>>   (lambda () (expand-add-abbrevs emacs-lisp-mode-abbrev-table elisp-expand-list)))
>> (add-hook 'lisp-interaction-mode-hook
>>   (lambda () (expand-add-abbrevs emacs-lisp-mode-abbrev-table elisp-expand-list)))
>> (global-set-key [remap dabbrev-expand] 'hippie-expand)
>>
>> This error persists even when calling the (try-expand-all-abbrevs nil) using eval expression the debug
>> log is as follows.
> It looks like hippie-expand doesn't support "special" abbrevs, those
> whose expansion is obtained by running a hook function (as opposed to
> just using the string that is the abbrev's expansion).  IOW,
> hippie-expand expects that abbrev-expansion returns a string, which is
> not what happens with "special" abbrevs.  And expand.el, where
> expand-add-abbrevs is defined, defines such "special" abbrevs.
>
> Patches to adapt hippie-expand to abbrevs created by expand.el are
> welcome.

  I got this working  in my config by defining a simple function to try 
abbrev if it exists and adding that to the hippie expand-try-functions

(defun try-expand-abbrev (old)
   "Try to expand abbrev if one exists at point."
   (unless old
     (expand-abbrev)))

(setq hippie-expand-try-functions-list
       (cons 'try-expand-abbrev
             (remove 'try-expand-abbrev hippie-expand-try-functions-list)))