Subject: Re: bug#44328: 27.1; [PATCH] Add expand-abbrev-maybe condition key binding

From: Zhu Zihao <[email-masked]>
Date: Tue, 03 Nov 2020 12:40:52 +0800

I'm afraid that a normal command can't do this. Please see following
example.

```
(defvar my-override-map (make-sparse-keymap))

(define-minor-mode my-keymap-override-mode
  ""
  :keymap my-override-map)

(defconst expand-abbrev-maybe
  '(menu-item "" expand-abbrev
    :filter (lambda (cmd) (and (abbrev--before-point) cmd))))

(define-key my-override-map (kbd "C-'") expand-abbrev-maybe)

(global-set-key (kbd "C-'") #'eww)

(define-abbrev emacs-lisp-mode-abbrev-table "lb" ";; -*- lexical-binding: t -*-")
```

I first create a minor mode for keymap overriding, then set the global
key C-' to eww. And bind expand-abbrev-maybe to the keymap of minor mode
my-keymap-override-mode.

And I define a abbrev "lb" in Elisp mode. then enable minor mode
my-override-map in Elisp mode. If my cursor is following "lb"(like
"lb|"), it will expand the abbrev, otherwise it will execute eww.

Now I change the key binding of C-' in global map(change to gnus). the
behaviour of keybinding in my-override-map will become "Expand abbrev if
possible otherwise execute gnus" 

Lars Ingebrigtsen writes:

> "Zhu Zihao" <[email-masked]> writes:
>
>> Actually, it's a menu-item definition, described in
>> https://www.gnu.org/software/emacs/manual/html_node/elisp/Extended-Menu-Items.html
>>
>> It can be bound to a keymap and use it like key bindings, it also support some
>> dynamic features which normal keybinding can't do, according to manual.
>
> OK, but a normal command would surely make more sense here?

-- 
Retrieve my PGP public key: https://meta.sr.ht/~citreu.pgp

Zihao