unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44328: 27.1; [PATCH] Add expand-abbrev-maybe condition key binding
@ 2020-10-30 14:32 Zhu Zihao
  2020-11-01 14:25 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Zhu Zihao @ 2020-10-30 14:32 UTC (permalink / raw)
  To: 44328

[-- Attachment #1: Type: text/plain, Size: 395 bytes --]


This patch add expand-abbrev-maybe. A conditional keybinding inspired
from YASnippet.

When bound to something like "TAB", it will expand abbrev if there's
some at point, it will do original binding(e.g. indent) if there's no
abbrev.

This is helpful for somebody doesn't like aggressive expand strategy in
abbrev-mode, but still doesn't want to give a exclusive keybinding for
expand-abbrev.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-conditonal-key-binding-expand-abbrev-maybe.patch --]
[-- Type: text/x-patch, Size: 2057 bytes --]

From 3df90b6c045d8f9e5e91890b44a96a9685e872ae Mon Sep 17 00:00:00 2001
From: Zhu Zihao <all_but_last@163.com>
Date: Fri, 30 Oct 2020 22:24:54 +0800
Subject: [PATCH] Add conditonal key binding expand-abbrev-maybe

A binding which will expand any existing abbrev at point and act like
original keybinding when there's none abbrev at point.

* lisp/abbrev.el (expand-abbrev-maybe): New variable.
* doc/emacs/abbrevs.texi (Abbrev Concepts): New vindex "expand-abbrev-maybe".
---
 doc/emacs/abbrevs.texi | 6 ++++++
 lisp/abbrev.el         | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/doc/emacs/abbrevs.texi b/doc/emacs/abbrevs.texi
index e3766aae9e..2d7b4e1698 100644
--- a/doc/emacs/abbrevs.texi
+++ b/doc/emacs/abbrevs.texi
@@ -210,6 +210,12 @@ Expanding Abbrevs
 unexpand-abbrev} to cancel the last expansion without deleting the
 terminating character.
 
+@vindex expand-abbrev-maybe
+  If you don't want to check expand for every @code{self-insert-command}
+like Abbrev mode. There's a variable describing a conditional key definition
+You can bind it to some key like @kbd{TAB}. It' ll expand abbrev if
+there's some abbrev at point, and act like usual @kbd{TAB} if there's not.
+
 @findex expand-region-abbrevs
   @kbd{M-x expand-region-abbrevs} searches through the region for defined
 abbrevs, and for each one found offers to replace it with its expansion.
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index f35c637eed..7d4bb9621f 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -978,6 +978,13 @@ expand-abbrev
       (if abbrev-suggest
           (abbrev--suggest-maybe-suggest))))
 
+(defconst expand-abbrev-maybe
+  '(menu-item "" expand-abbrev
+    :filter (lambda (cmd) (and (abbrev--before-point) cmd)))
+  "A conditional key definition for `expand-abbrev'.
+When this was bound, it will expand abbrev at point if there're any possible
+abbrev.")
+
 (defun abbrev--default-expand ()
   "Default function to use for `abbrev-expand-function'.
 This also respects the obsolete wrapper hook `abbrev-expand-functions'.
-- 
2.29.1


[-- Attachment #3.1: Type: text/plain, Size: 76 bytes --]


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

Zihao

[-- Attachment #3.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 515 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-13 11:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-05-13 11:25         ` Lars Ingebrigtsen

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).