GNU bug report logs -
#44328
27.1; [PATCH] Add expand-abbrev-maybe condition key binding
Previous Next
Reported by: Zhu Zihao <all_but_last <at> 163.com>
Date: Fri, 30 Oct 2020 14:49:02 UTC
Severity: normal
Tags: patch, wontfix
Found in version 27.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 44328 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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" <all_but_last <at> 163.com> 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
[signature.asc (application/pgp-signature, inline)]
This bug report was last modified 4 years and 12 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.