Abbrev suggestions - feedback appreciated

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Abbrev suggestions - feedback appreciated

Mathias Dahl-3
Hi emacs-devel!

I want to have feedback on a small addition I have made to Emacs abbrev
functionality. First some background...

Some days back I was typing away in Emacs and after typing some hard to
spell word I realized that I probably had an abbrev defined for that
word. I checked by abbrev definitions and, yes, it was there. It turns
out I had many defined abbrevs that I had forgotten about, so I was
typing more than I needed. This got me thinking that it would be nice if
Emacs could tell me when I have typed a word that exists as an abbrev
expansion. After some research in abbrev.el I finally got something to
work, and you can find it below.

I would like to have people's comments on the idea, and know if this
might allredy exist (I tried to find something similar but couldn't), and
also if there are any performance problems or other in my code. The
internals of abbrevs are dark and mysterious to me, so I might miss some
crucial things. But, the code seems to do what I want it to.

Also, if people like this idea, perhaps it could be added to Emacs
proper. Surely it can live on its life as a separate library on Melpa,
Elpa or other place, but the code is quite short and this feels like
something that could be a simple option/toggle in Emacs standard abbrev
functionality. I have papers in place if this is something people would
like.

Without further ado, here is the current code I have:

;;; absug.el --- Suggest an abbrev based on the word before point

;; Copyright stuff to be added later...

;; Author: Mathias Dahl ([hidden email])

;;; Commentary:

;; This library helps the user remember defined abbrevs by suggesting
;; them after having typed an abbrev expansion manually.

;; For example, if the user has defined the abbrev `doc' with the
;; expansion `document', if the user manually types `document' with
;; `abbrev-mode' active, a message will be presented suggesting to use
;; the defined abbrev `doc' instead.

;; To install, load or require this file/library and also add the
;; following code to your .emacs or init.el file:

;; (absug-enable)

;; (It is also a command you can call interactively)

;; You can interactively turn off abbrev suggestion by calling the
;; command `absug-disable'.

;;; Code:

(defun absug-word-before-point ()
  "Return the word before point."
  (let ((lim (point))
        start end)
    (backward-word 1)
    (setq start (point))
    (forward-word 1)
    (setq end (min (point) lim))
    (buffer-substring-no-properties start end)))

(defun absug-get-active-tables-including-parents ()
  "Return a list of all active abbrev tables, including parent tables."
  (let* ((tables (abbrev--active-tables))
         (all tables))
    (dolist (table tables)
      (setq all (append (abbrev-table-get table :parents) all)))
    all))

(defun absug-get-active-abbrev-expansions ()
  "Return a list of all the active abbrev expansions.
Includes expansions from parent abbrev tables."
  (let (expansions)
    (dolist (table (absug-get-active-tables-including-parents))
      (mapatoms (lambda (e)
                  (let ((value (symbol-value (abbrev--symbol e table))))
                    (if value
                        (setq expansions
                              (cons (cons value (symbol-name e))
                                    expansions)))))
                table))
    expansions))

(defun absug-maybe-suggest ()
  "Suggest an abbrev to the user based on the word before point."
  (let* ((word (absug-word-before-point))
         (expansions (absug-get-active-abbrev-expansions))
         (abbrev (assoc word expansions)))
    (if abbrev
        (message "Abbrev suggestion: The word `%s' has the abbrev
`%s' defined" (car abbrev) (cdr abbrev)))))

(defun absug-default-expand ()
  "My version to use for `abbrev-expand-function'.
If no abbrev expansion is found by `abbrev--default-expand', see
if there is an abbrev defined for the word before point, and
suggest it to the user."
  (unless (abbrev--default-expand)
    (absug-maybe-suggest)))

(defun absug-disable ()
  "Disable abbrev suggestions"
  (interactive)
  (setq abbrev-expand-function #'abbrev--default-expand))

(defun absug-enable ()
  "Enable abbrev suggestions"
  (interactive)
  (setq abbrev-expand-function #'absug-default-expand))

(provide 'absug)

;;; absug.el ends here


Thanks!

/Mathias

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Eli Zaretskii
> From: Mathias Dahl <[hidden email]>
> Date: Sat, 16 Sep 2017 09:51:53 +0200
>
> Some days back I was typing away in Emacs and after typing some hard to
> spell word I realized that I probably had an abbrev defined for that
> word. I checked by abbrev definitions and, yes, it was there. It turns
> out I had many defined abbrevs that I had forgotten about, so I was
> typing more than I needed. This got me thinking that it would be nice if
> Emacs could tell me when I have typed a word that exists as an abbrev
> expansion. After some research in abbrev.el I finally got something to
> work, and you can find it below.
>
> I would like to have people's comments on the idea, and know if this
> might allredy exist (I tried to find something similar but couldn't), and
> also if there are any performance problems or other in my code. The
> internals of abbrevs are dark and mysterious to me, so I might miss some
> crucial things. But, the code seems to do what I want it to.
>
> Also, if people like this idea, perhaps it could be added to Emacs
> proper. Surely it can live on its life as a separate library on Melpa,
> Elpa or other place, but the code is quite short and this feels like
> something that could be a simple option/toggle in Emacs standard abbrev
> functionality. I have papers in place if this is something people would
> like.

Why not add this as an optional feature to abbrev.el, conditional on
some defcustom?

> (defun absug-maybe-suggest ()
>   "Suggest an abbrev to the user based on the word before point."
>   (let* ((word (absug-word-before-point))
>          (expansions (absug-get-active-abbrev-expansions))
>          (abbrev (assoc word expansions)))
>     (if abbrev
>         (message "Abbrev suggestion: The word `%s' has the abbrev
> `%s' defined" (car abbrev) (cdr abbrev)))))

I'd suggest to make the message text shorter, to make the probability
of its becoming longer than the echo-area width, which would resize
the mini-window and cause an annoying redisplay.  I'd just drop the
part before the colon, as the rest already says there is an abbrev.

Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Stefan Monnier
In reply to this post by Mathias Dahl-3
> (defun absug-maybe-suggest ()
>   "Suggest an abbrev to the user based on the word before point."
>   (let* ((word (absug-word-before-point))
>          (expansions (absug-get-active-abbrev-expansions))
>          (abbrev (assoc word expansions)))
>     (if abbrev
>         (message "Abbrev suggestion: The word `%s' has the abbrev
> `%s' defined" (car abbrev) (cdr abbrev)))))

I like the feature.  Here are some comments:

- The expansion is not necessarily a "word".
- The `expansions` list is built only to then pass it to `assoc`.
  You could avoid constructing the list by passing `word` to
  absug-get-active-abbrev-expansions and have it check equality as it goes.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
In reply to this post by Eli Zaretskii
Hi Eli, thanks for your feedback on this!

Why not add this as an optional feature to abbrev.el, conditional on
some defcustom?

I should have mentioned that that is what I had in mind, actually, 
if this would ever be included in Emacs.

>         (message "Abbrev suggestion: The word `%s' has the abbrev
> `%s' defined" (car abbrev) (cdr abbrev)))))

I'd suggest to make the message text shorter, to make the probability
of its becoming longer than the echo-area width, which would resize
the mini-window and cause an annoying redisplay.  I'd just drop the
part before the colon, as the rest already says there is an abbrev.

I changed that to:

        (message "You can write `%s' using the abbrev `%s'."
                 (car abbrev) (cdr abbrev)))))

I tried to make it similar to how we "hint" users about keybindings to
commands.


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
In reply to this post by Stefan Monnier
Hi Stefan, thanks for your comments.

I like the feature.  Here are some comments:

- The expansion is not necessarily a "word".

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.

- The `expansions` list is built only to then pass it to `assoc`.
  You could avoid constructing the list by passing `word` to
  absug-get-active-abbrev-expansions and have it check equality as it goes.

That's a good optimization, thanks! At least as long as I am not trying
to tackle multi-word expansions. In that case, I don't know on
beforehand how many words to match. Again, surely possible to
solve... One way might be to save not one but, say, ten previous words,
and send that in to the function that will look for expansions matching
that. It would of course break on eleven words and above...

Any clever ideas? :) I might surely be able to do this, but I am also concerned
about performance here.

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
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...


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Stefan Monnier
In reply to this post by Mathias Dahl-3
>> You could avoid constructing the list by passing `word` to
>> absug-get-active-abbrev-expansions and have it check equality as it
>> goes.
> That's a good optimization, thanks! At least as long as I am not trying
> to tackle multi-word expansions. In that case, I don't know on
> beforehand how many words to match. Again, surely possible to
> solve... One way might be to save not one but, say, ten previous words,
> and send that in to the function that will look for expansions matching
> that. It would of course break on eleven words and above...
> Any clever ideas?

Actually, my "clever" idea was that you don't read any word at all: just
go though the existing abbreviations, and check for each one of the if
the text before point matches the expansion.

Admittedly, I don't think we currently have a fast implementation of the
equivalent of (looking-back (regexp-quote expansion)), so I don't know
how well it will perform.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
Actually, my "clever" idea was that you don't read any word at all: just
go though the existing abbreviations, and check for each one of the if
the text before point matches the expansion.

Admittedly, I don't think we currently have a fast implementation of the
equivalent of (looking-back (regexp-quote expansion)), so I don't know
how well it will perform.

My simple function `asug-get-previous-words' function performs quite well,
it seems. I could not get `looking-back' to work across lines. It was very quick
though, when words was on the same line.

Also, collecting all active abbrev expansions was also very fast (1000 runs
takes 0.1 on my not very hot PC) so I did not bother with that optimization. But
perhaps I will experiment a bit with that too.

All in all this seems to turn out quite nicely. I will try to integrate it properly in
abbrev.el and add some option there to toggle this feature on.

Thanks for the pointers!




Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Kaushal Modi
Hi Mathias,

This will be a pretty cool feature. 

I see just one caveat. I don't use abbrev for "auto-correct", but I know that many folks do[1].

So people could have abbrev entries like "eamcs" that "expand" to "emacs". So with this feature, the user will be suggested to type "eamcs" each time they correctly type "emacs"?

If so, can the suggestion be enabled only when the abbreviation is shorter than the expansion by N number of characters, where that N can be set using a defcustom? (I would default that to 2 or 3). 

--

Kaushal Modi

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
Hi Mathias,

Hi, and thanks for your comments!

This will be a pretty cool feature. 

I thought so too :)
 
I see just one caveat. I don't use abbrev for "auto-correct", but I know that many folks do[1].

Neither do I, mostly (I have a few "corrections" as well, but mostly I used it to type long or "hard" words using fewer characters.)

So people could have abbrev entries like "eamcs" that "expand" to "emacs". So with this feature, the user will be suggested to type "eamcs" each time they correctly type "emacs"?

Yes, or the last defined abbrev for "emacs" anyway (if there are more than one).
 
If so, can the suggestion be enabled only when the abbreviation is shorter than the expansion by N number of characters, where that N can be set using a defcustom? (I would default that to 2 or 3). 

It would be possible to have an option like that, or similar. The option could keep the diff in number of characters or the diff in percentage, or whatever clever thing we want. I will try to implement it.

Also, someone mailed me about the scenario where there are more than one abbrev for the same expansion. Right now, you will get a suggestion to use the most recently defined abbrev. I wonder how useful it would be to see the full list of abbrevs that might expand to a certain expansion... For me, the primary idea is to remind me that I have at least one abbrev defined for a certain expansion. If there are more than one, the reminder is enough, at least for me. I would probably have a look (M-x edit-abbrevs RET) to see what I have defined.

Does anyone else here think it would be useful to list all abbrevs that expand to a certain expansion? Surely it would be doable, but it would also be slower.

/Mathias


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Stefan Monnier
> Also, someone mailed me about the scenario where there are more than one
> abbrev for the same expansion. Right now, you will get a suggestion to use
> the most recently defined abbrev. I wonder how useful it would be to see
> the full list of abbrevs that might expand to a certain expansion...

I think it's enough to make sure we show the /shortest/ abbrev.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
> Also, someone mailed me about the scenario where there are more than one
> abbrev for the same expansion. Right now, you will get a suggestion to use
> the most recently defined abbrev. I wonder how useful it would be to see
> the full list of abbrevs that might expand to a certain expansion...

I think it's enough to make sure we show the /shortest/ abbrev.

I was able to implement that quite easily. The only worry I have is that
it might be slow, or I know it is slow-er at least since I need to go
through all active abbrev expansions to see if there is any shorter
one. I used benchmark-run 1000 times on one of the core functions though
and it takes less than 0.1 second on my not very new PC, so perhaps I
should not worry. I have very few abbrevs though... Should I be worried
about performance? We don't want the user's typing to be affected by this.


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
Hi again,

Please find below the latest version. It has the option requested
earlier and I also included the command `absug-report' that the user can
use to see what expansions that has been typed manually, and how many
times.

I'm starting to be quite happy with this now. This is still a separate
package, but if there is still interest I can try to merge the code into
abbrev.el (if so, I have some renaming to do...) and make it into an
option there, as suggested by Eli earlier. Then I can post a patch here.

Comments?

/Mathias

;;; absug.el --- Suggest an abbrev based on the word(s) before point

;; Copyright stuff to be added later...

;; Author: Mathias Dahl ([hidden email])

;;; Commentary:

;; This library helps the user remember defined abbrevs by suggesting
;; them after having typed an abbrev expansion manually.

;; For example, if the user has defined the abbrev `doc' with the
;; expansion `document', if the user manually types `document' with
;; `abbrev-mode' active, a message will be presented suggesting to use
;; the defined abbrev `doc' instead.

;; To install, load or require this file/library and also add the
;; following code to your .emacs or init.el file:

;; (absug-enable)

;; (It is also a command you can call interactively)

;; You can interactively turn off abbrev suggestions by calling the
;; command `absug-disable'.

;;; Ideas:

;; - Think about different ways to notify the user
;; - Display a report of statistics of abbrevs the user have forgotten

;;; Code:

(defcustom absug-hint-threshold 3
  "Threshold for when to inform the user that there is an abbrev.
The threshold is the number of characters that differs between
the length of the abbrev and the length of the expansion.  The
thinking is that if the expansion is only one or a few characters
longer than the abbrev, the benefit of informing the user is not
that big.  If you always want to be informed, set this value to
`0' or less."
  :type 'number
  :group 'abbrev-mode
  :group 'convenience)

(defun absug-get-active-tables-including-parents ()
  "Return a list of all active abbrev tables, including parent tables."
  (let* ((tables (abbrev--active-tables))
         (all tables))
    (dolist (table tables)
      (setq all (append (abbrev-table-get table :parents) all)))
    all))

(defun absug-get-active-abbrev-expansions ()
  "Return a list of all the active abbrev expansions.
Includes expansions from parent abbrev tables."
  (let (expansions)
    (dolist (table (absug-get-active-tables-including-parents))
      (mapatoms (lambda (e)
                  (let ((value (symbol-value (abbrev--symbol e table))))
                    (when value
                      (setq expansions
                            (cons (cons value (symbol-name e))
                                  expansions)))))
                table))
    expansions))

(defun absug-count-words (expansion)
  "Return the number of words in EXPANSION.
Expansion is a string of one or more words."
  (length (split-string expansion " " t)))

(defun absug-get-previous-words (n)
  "Return the previous N words, spaces included.
Changes newlines into spaces."
  (let ((end (point))
        words)
    (save-excursion
      (backward-word n)
      (replace-regexp-in-string
       "\\s " " "
       (buffer-substring-no-properties (point) end)))))

(defun absug-above-threshold (expansion)
  "Return t if we are above the threshold.
EXPANSION is a cons cell where the car is the expansion and the
cdr is the abbrev."
  (>= (- (length (car expansion))
         (length (cdr expansion)))
      absug-hint-threshold))

(defvar absug-saved-recommendations nil
  "Keeps a list of expansions that have abbrevs defined.
The user can show this list by calling
`absug-show-recommendations'.")

(defun absug-inform-user (expansion)
  "Display a message to the user about the existing abbrev.
EXPANSION is a cons cell where the `car' is the expansion and the
`cdr' is the abbrev."
  (run-with-idle-timer
   2 nil
   `(lambda ()
      (message "You can write `%s' using the abbrev `%s'."
               ,(car expansion) ,(cdr expansion))))
  (setq absug-saved-recommendations
        (cons expansion absug-saved-recommendations)))

(defun absug-shortest-abbrev (new current)
  "Return the shortest abbrev.
NEW and CURRENT are cons cells where the `car' is the expansion
and the `cdr' is the abbrev."
  (if (not current)
      new
    (if (< (length (cdr new))
           (length (cdr current)))
        new
      current)))

(defun absug-maybe-suggest ()
  "Suggest an abbrev to the user based on the word(s) before point.
Uses `absug-hint-threshold' to find out if the user should be
informed about the existing abbrev."
  (let (words abbrev-found expansion word-count)
    (dolist (expansion (absug-get-active-abbrev-expansions))
      (setq word-count (absug-count-words (car expansion))
            words (absug-get-previous-words word-count))
      (let ((case-fold t))
        (when (and (> word-count 0)
                   (string-match (car expansion) words)
                   (absug-above-threshold expansion))
          (setq abbrev-found (absug-shortest-abbrev
                              expansion abbrev-found)))))
    (when abbrev-found
      (absug-inform-user abbrev-found))))

(defun absug-default-expand ()
  "My version to use for `abbrev-expand-function'.
If no abbrev expansion is found by `abbrev--default-expand', see
if there is an abbrev defined for the word before point, and
suggest it to the user."
  (unless (abbrev--default-expand)
    (absug-maybe-suggest)))

(defun absug-get-totals ()
  "Return a list of all expansions and their usage.
Each expansion is a cons cell where the `car' is the expansion
and the `cdr' is the number of times the expansion has been
typed."
  (let (total cell)
    (dolist (expansion absug-saved-recommendations)
      (if (not (assoc (car expansion) total))
          (add-to-list 'total (cons (car expansion) 1))
        (setq cell (assoc (car expansion) total))
        (setcdr cell (1+ (cdr cell)))))
    total))

(defun absug-report ()
  "Show the user a report of abbrevs he could have used."
  (interactive)
  (let ((totals (absug-get-totals))
        (buf (get-buffer-create "*absug*")))
    (set-buffer buf)
    (erase-buffer)
    (insert "** Abbrev expansion usage **

Below is a list of expansions for which abbrevs are defined, and
the number of times the expansion was typed manually. To display
and edit all abbrevs, type `M-x edit-abbrevs RET'\n\n")
    (dolist (expansion totals)
      (insert (format " %s: %d\n" (car expansion) (cdr expansion))))
    (display-buffer buf)))

(defun absug-disable ()
  "Disable abbrev suggestions."
  (interactive)
  (setq abbrev-expand-function #'abbrev--default-expand))

(defun absug-enable ()
  "Enable abbrev suggestions."
  (interactive)
  (setq abbrev-expand-function #'absug-default-expand))

(provide 'absug)

;;; absug.el ends here

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Ian Dunn
>>>>> "Mathias" == Mathias Dahl <[hidden email]> writes:

    Mathias> Hi again, Please find below the latest version. It has the
    Mathias> option requested earlier and I also included the command
    Mathias> `absug-report' that the user can use to see what expansions
    Mathias> that has been typed manually, and how many times.

    Mathias> I'm starting to be quite happy with this now. This is still
    Mathias> a separate package, but if there is still interest I can
    Mathias> try to merge the code into abbrev.el (if so, I have some
    Mathias> renaming to do...) and make it into an option there, as
    Mathias> suggested by Eli earlier. Then I can post a patch here.

    Mathias> Comments?

Two.

1. This looks amazing.  As an avid user of abbrevs, having something remind me when I've created a new abbrev and no longer need to type something out that was bugging me enough to make an abbrev will be great.

2. Having this be controlled by some property of abbrev tables and/or abbrevs themselves would be ideal, similar to the case-fixed property.  That way the expansions of auto-correct[1] and captain[2] abbrevs won't nag people all the time.

[1] https://elpa.gnu.org/packages/auto-correct.html
[2] https://elpa.gnu.org/packages/captain.html

--
Ian Dunn

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Stefan Monnier
In reply to this post by Mathias Dahl-3
> I was able to implement that quite easily. The only worry I have is that
> it might be slow, or I know it is slow-er at least since I need to go
> through all active abbrev expansions to see if there is any shorter
> one.

I don't think that should be slower than when you go through all abbrevs
and conclude that there aren't any that apply, which AFAICT is the most
common case.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Stefan Monnier
In reply to this post by Ian Dunn
> 2. Having this be controlled by some property of abbrev tables and/or
> abbrevs themselves would be ideal, similar to the case-fixed property.
> That way the expansions of auto-correct[1] and captain[2] abbrevs won't nag
> people all the time.
>
> [1] https://elpa.gnu.org/packages/auto-correct.html
> [2] https://elpa.gnu.org/packages/captain.html

For Captain, the abbrev and its "expansion" should have the same length,
so absug-hint-threshold should already skip them.

For auto-correct, it might be the case that the wrong spelling is
shorter by absug-hint-threshold, but then you could also argue that if
you often misspell a word and it gets auto-corrected and the wrong
spelling is shorter, you might take it as a feature and consciously use
the shorter/wrong spelling and rely on the abbrev to auto correct it.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Seweryn Kokot-3
In reply to this post by Mathias Dahl-3
Hi Mathias and others,
Regarding the performance, in fact in my case with more than 2600 abbrevs, the message is displayed in more than 1 second, which is quite slow. My processor is core i5.
Regards,
Seweryn Kokot
Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
Regarding the performance, in fact in my case with more than 2600 abbrevs, the message is displayed in more than 1 second, which is quite slow. My processor is core i5.

If you mean that it takes a second before the message appears, that is on purpose. The message will be displayed when Emacs has been idle for 2 seconds. Probably I should make that 1 second. I could inform the user straight away but I was thinking that the user would miss the message then. I'm also thinking if I should "queue up" all the messages, if there are more than one, and show all when the user is idle. Perhaps, if more than one message has been queued up, I should recommend the user to run M-x absug-report to show them all?

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Mathias Dahl-3
In reply to this post by Stefan Monnier
> I was able to implement that quite easily. The only worry I have is that
> it might be slow, or I know it is slow-er at least since I need to go
> through all active abbrev expansions to see if there is any shorter
> one.

I don't think that should be slower than when you go through all abbrevs
and conclude that there aren't any that apply, which AFAICT is the most
common case.

You're very right, of course :) Sometimes you don't see the forest for the trees...

Reply | Threaded
Open this post in threaded view
|

Re: Abbrev suggestions - feedback appreciated

Ian Dunn
In reply to this post by Stefan Monnier
>>>>> "Stefan" == Stefan Monnier <[hidden email]> writes:

    >> 2. Having this be controlled by some property of abbrev tables
    >> and/or abbrevs themselves would be ideal, similar to the
    >> case-fixed property.  That way the expansions of auto-correct[1]
    >> and captain[2] abbrevs won't nag people all the time.
    >>
    >> [1] https://elpa.gnu.org/packages/auto-correct.html [2]
    >> https://elpa.gnu.org/packages/captain.html

    Stefan> For Captain, the abbrev and its "expansion" should have the
    Stefan> same length, so absug-hint-threshold should already skip
    Stefan> them.

    Stefan> For auto-correct, it might be the case that the wrong
    Stefan> spelling is shorter by absug-hint-threshold, but then you
    Stefan> could also argue that if you often misspell a word and it
    Stefan> gets auto-corrected and the wrong spelling is shorter, you
    Stefan> might take it as a feature and consciously use the
    Stefan> shorter/wrong spelling and rely on the abbrev to auto
    Stefan> correct it.

I stand corrected.  My only other suggestion would be to use add-function on abbrev-expand-function instead of setting it directly to avoid overwriting other packages that may need it.  Something like the following:



--
Ian Dunn

attachment0 (74 bytes) Download Attachment