From: Allen Li <darkfeline@felesatra.moe>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 36243@debbugs.gnu.org
Subject: bug#36243: 26.2; defining inverse abbrevs include space
Date: Mon, 17 Jun 2019 12:23:02 -0700 [thread overview]
Message-ID: <CADbSrJybFVie8Vah4UaUOQFcxF6CxpfWp1aLCS_U=YAccmbsTA@mail.gmail.com> (raw)
In-Reply-To: <85y320l19n.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 939 bytes --]
Thanks for suggesting skip-syntax-backward, see new patch.
On Mon, Jun 17, 2019 at 7:44 AM Noam Postavsky <npostavs@gmail.com> wrote:
>
> Allen Li <darkfeline@felesatra.moe> writes:
>
> > Defining an inverse abbrev in a buffer like so (@ is point):
> >
> > some text foo @
> >
> > C-x a i l find outer otter RET
> >
> > defines an abbrev "foo " -> "find outer otter"
>
> > * lisp/abbrev.el (inverse-add-abbrev): Skip trailing nonword
> > characters when defining abbrev.
>
> > (defun inverse-add-abbrev (table type arg)
> > (let (name exp start end)
> > (save-excursion
> > - (forward-word (1+ (- arg)))
> > + (if (<= arg 0)
> > + (forward-word (1+ (- arg)))
> > + (forward-word (- arg))
> > + (forward-word))
> > (setq end (point))
> > (backward-word 1)
>
> This seems like a somewhat obfuscated way of skipping nonword
> characters. How about using skip-syntax-backward instead?
[-- Attachment #2: 0001-Fix-defining-inverse-abbrevs-on-previous-words.patch --]
[-- Type: text/x-patch, Size: 2621 bytes --]
From 91d4c9328d6a17b77a8d3a86495b1e17fe363d1c Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Sun, 16 Jun 2019 03:32:02 -0700
Subject: [PATCH] Fix defining inverse abbrevs on previous words
* lisp/abbrev.el (inverse-add-abbrev): Skip trailing nonword
characters when defining abbrev.
* test/lisp/abbrev-tests.el (abbrev-edit-save-to-file-test): Add
regression tests.
---
lisp/abbrev.el | 1 +
test/lisp/abbrev-tests.el | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index aebf65e0f7..c0854b99fe 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -354,6 +354,7 @@ inverse-add-abbrev
(let (name exp start end)
(save-excursion
(forward-word (1+ (- arg)))
+ (skip-syntax-backward "^w")
(setq end (point))
(backward-word 1)
(setq start (point)
diff --git a/test/lisp/abbrev-tests.el b/test/lisp/abbrev-tests.el
index 800c9aac33..33a5ec7dab 100644
--- a/test/lisp/abbrev-tests.el
+++ b/test/lisp/abbrev-tests.el
@@ -249,6 +249,34 @@ setup-test-abbrev-table
(abbrev-expansion "s-a-t" ert-save-test-table)))
(delete-file temp-test-file))))
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword ()
+ "Test that adding an inverse abbrev skips trailing nonword characters."
+ (let ((table (make-abbrev-table)))
+ (with-temp-buffer
+ (insert "some text foo ")
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" 1)))
+ (should (string= (abbrev-expansion "foo" table) "bar"))))
+
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword/postiive-arg ()
+ "Test that adding an inverse abbrev skips trailing nonword characters."
+ (let ((table (make-abbrev-table)))
+ (with-temp-buffer
+ (insert "some text foo ")
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" 2)))
+ (should (string= (abbrev-expansion "text" table) "bar"))))
+
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword/negative-arg ()
+ "Test that adding an inverse abbrev skips trailing nonword characters."
+ (let ((table (make-abbrev-table)))
+ (with-temp-buffer
+ (insert "some text foo")
+ (goto-char (point-min))
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" -1)))
+ (should (string= (abbrev-expansion "text" table) "bar"))))
+
(provide 'abbrev-tests)
;;; abbrev-tests.el ends here
--
2.22.0.410.gd8fdbe21b5-goog
next prev parent reply other threads:[~2019-06-17 19:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-16 10:35 bug#36243: 26.2; defining inverse abbrevs include space Allen Li
2019-06-17 14:44 ` Noam Postavsky
2019-06-17 19:23 ` Allen Li [this message]
2019-06-21 18:30 ` Allen Li
2019-06-22 23:35 ` Noam Postavsky
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADbSrJybFVie8Vah4UaUOQFcxF6CxpfWp1aLCS_U=YAccmbsTA@mail.gmail.com' \
--to=darkfeline@felesatra.moe \
--cc=36243@debbugs.gnu.org \
--cc=npostavs@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.