all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mathias Dahl <mathias.dahl@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Abbrev suggestions - feedback appreciated
Date: Sun, 17 Sep 2017 16:03:26 +0200	[thread overview]
Message-ID: <CABrcCQ4yzhgOJNuUrm+75Tw7CeQ_y2QN6udVqcYt4dWBxt_XdA@mail.gmail.com> (raw)
In-Reply-To: <CABrcCQ7dzKBgGqPNunYoLibs0gZnpo=jvC4hcFFDNnW32fsF4g@mail.gmail.com>

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

>
> True. I thought about that and concluded that it would be a lot harder
> to look for more than one words, matching a certain expansion. It will
> be especially tricky, I think, if the words the user types and which
> match an extension, spans more than one line. Of course not impossible but
> I thought I would start with the easy and probably quite common use
> case.
>

Okay, so... Turns out it was not that hard... :)

With two helper functions I could rewrite the suggest function quite nicely:

(defun asug-count-words (expansion)
  (length (split-string expansion " " t)))

(defun asug-get-previous-words (n)
  (let ((end (point))
        words)
    (save-excursion
      (backward-word n)
      (replace-regexp-in-string
       "[\n\r]" " "
       (buffer-substring-no-properties (point) end)))))

(defun absug-maybe-suggest ()
  "Suggest an abbrev to the user based on the word(s) before point."
  (let ((expansions (absug-get-active-abbrev-expansions))
         words found expansion word-count)
    (while (and expansions
                (not found))
      (setq expansion (pop expansions))
      (when expansion
        (setq word-count (asug-count-words (car expansion))
              words (asug-get-previous-words word-count))
        (when (and (> word-count 0)
                   (string= words (car expansion)))
          (setq found t)
          (message "You can write `%s' using the abbrev `%s'."
                   (car expansion) (cdr expansion)))))))

It works for abbrevs that has an expansion with multiple words and
it also works across lines.

Now I will clean this up a bit and checkdoc it...

[-- Attachment #2: Type: text/html, Size: 2573 bytes --]

  reply	other threads:[~2017-09-17 14:03 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-16  7:51 Abbrev suggestions - feedback appreciated Mathias Dahl
2017-09-16  8:46 ` Eli Zaretskii
2017-09-17 13:15   ` Mathias Dahl
2017-09-16 13:22 ` Stefan Monnier
2017-09-17 13:22   ` Mathias Dahl
2017-09-17 14:03     ` Mathias Dahl [this message]
2017-09-17 21:23     ` Stefan Monnier
2017-09-17 21:56       ` Mathias Dahl
2017-10-03 12:51         ` Kaushal Modi
2017-10-07 15:13           ` Mathias Dahl
2017-10-07 15:29             ` Stefan Monnier
2017-10-07 17:18               ` Mathias Dahl
2017-10-07 18:40                 ` Mathias Dahl
2017-10-07 22:29                   ` Ian Dunn
2017-10-07 22:44                     ` Stefan Monnier
2017-10-08 16:38                       ` Ian Dunn
2018-09-17 21:48                         ` Mathias Dahl
2018-09-18  2:05                           ` Stefan Monnier
2020-05-11 21:37                             ` Mathias Dahl
2020-05-11 22:39                               ` Mathias Dahl
2020-05-11 22:58                               ` Stefan Monnier
2020-05-16 22:10                                 ` Mathias Dahl
2020-05-16 22:22                                   ` Mathias Dahl
2020-05-17  3:13                                     ` Stefan Monnier
2020-05-17 14:59                                       ` Mathias Dahl
2020-05-17 15:45                                         ` Eli Zaretskii
2020-05-17 18:43                                           ` Mathias Dahl
2020-05-17 21:20                                             ` Stefan Monnier
2020-05-18 22:00                                               ` Mathias Dahl
2020-06-04 20:14                                                 ` Mathias Dahl
2017-10-07 22:40                 ` Stefan Monnier
2017-10-08 15:28                   ` Mathias Dahl
  -- strict thread matches above, loose matches on Subject: below --
2017-10-08  8:15 Seweryn Kokot
2017-10-08 15:25 ` Mathias Dahl

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=CABrcCQ4yzhgOJNuUrm+75Tw7CeQ_y2QN6udVqcYt4dWBxt_XdA@mail.gmail.com \
    --to=mathias.dahl@gmail.com \
    --cc=emacs-devel@gnu.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 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.