From: Zhu Zihao <all_but_last@163.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 44328@debbugs.gnu.org
Subject: bug#44328: 27.1; [PATCH] Add expand-abbrev-maybe condition key binding
Date: Tue, 03 Nov 2020 12:40:52 +0800 [thread overview]
Message-ID: <86eelbaw8b.fsf@163.com> (raw)
In-Reply-To: <87r1pb6akn.fsf@gnus.org>
[-- Attachment #1: Type: text/plain, Size: 1626 bytes --]
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@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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 515 bytes --]
next prev parent reply other threads:[~2020-11-03 4:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-30 14:32 bug#44328: 27.1; [PATCH] Add expand-abbrev-maybe condition key binding Zhu Zihao
2020-11-01 14:25 ` Lars Ingebrigtsen
2020-11-02 5:41 ` bug#44328: " Zhu Zihao
2020-11-02 15:30 ` Lars Ingebrigtsen
2020-11-03 4:40 ` Zhu Zihao [this message]
2021-05-13 11:25 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86eelbaw8b.fsf@163.com \
--to=all_but_last@163.com \
--cc=44328@debbugs.gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).