• RIP pre-abbrev-expand-hook ?

    From Jim Diamond@JimDiamond@ns.sympatico.ca to gnu.emacs.help on Tue Mar 7 21:13:06 2023
    From Newsgroup: gnu.emacs.help

    A long, long time ago I started using a function (John Wiegley's
    auto-correct function) which, up until Emacs 28, worked by defining a
    function to maybe correct a word, and then
    (add-hook 'pre-abbrev-expand-hook 'fix-transposed-characters)

    I now find out that pre-abbrev-expand-hook was obsoleted quite some time
    ago, but it worked until I upgraded to emacs 28.2, and so I never noticed
    this obsoletion until now.

    I still want to use this function, but it isn't clear to me how to use it.
    I tried
    (add-hook 'abbrev-expand-functions 'fix-transposed-characters)
    but I was then rewarded with

    apply: Wrong number of arguments: (lambda nil "Fix any transposed characters in the input." (catch 'done (if (and (memq major-mode correct-words-applicable-modes) (not (auto-correct-check-word))) (let ((end (point))) (backward-word 1) (if (not (looking-at "[a-zA-Z]+\\([ ]\\|$\\)")) (progn (goto-char end) (throw 'done t))) (if (and (equal major-mode 'plain-tex-mode) (if (not (bobp)) (save-excursion (backward-char 1) (looking-at "\\\\")) nil)) (progn (goto-char end) (throw 'done t))) (let ((case-fold-search nil)) (if (looking-at "[A-Z]+\\([ ]\\|$\\)") (progn (goto-char end) (throw 'done t)))) (forward-char 1) (while (< (point) end) (transpose-chars nil) (if (auto-correct-check-word) (progn (goto-char end) (throw 'done t)) (forward-char -1) (transpose-chars nil))))))), 1

    which isn't all that helpful to me.

    Evidently all these years of happily using emacs has still not caused me to learn enough elisp for me to debug this one.

    Is there anyone here who can enlighten me on how to get this working again?

    Thanks.

    Jim

    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Manuel Giraud@manuel@ledu-giraud.fr to gnu.emacs.help on Fri Mar 10 13:33:11 2023
    From Newsgroup: gnu.emacs.help

    Jim Diamond <JimDiamond@ns.sympatico.ca> writes:

    A long, long time ago I started using a function (John Wiegley's
    auto-correct function) which, up until Emacs 28, worked by defining a function to maybe correct a word, and then
    (add-hook 'pre-abbrev-expand-hook 'fix-transposed-characters)

    I now find out that pre-abbrev-expand-hook was obsoleted quite some time
    ago, but it worked until I upgraded to emacs 28.2, and so I never noticed this obsoletion until now.

    I still want to use this function, but it isn't clear to me how to use it.
    I tried
    (add-hook 'abbrev-expand-functions 'fix-transposed-characters)
    but I was then rewarded with

    Hi,

    It seems that your 'fix-transposed-characters' function does not require
    any arguments and it might not be the case for functions in 'abbrev-expand-functions'.

    Anyway, there is other obsolescence going on ('abbrev-expand-functions'
    for example). So I think the new way of doing what you are trying to
    achieve is the following:

    (advice-add abbrev-expand-function :before (lambda () (message "foo")))

    The before lambda has no arguments so maybe you could replace it by 'fix-transposed-charactersrCa but I don't understand what 'fix-transposed-characters' is doing, if the context will be what's
    needed, etc. So try at your own risk.
    --
    Manuel Giraud
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Jim Diamond@JimDiamond@ns.sympatico.ca to gnu.emacs.help on Mon Mar 13 20:29:50 2023
    From Newsgroup: gnu.emacs.help

    On 2023-03-10 at 08:33 AST, Manuel Giraud <manuel@ledu-giraud.fr> wrote:
    Jim Diamond <JimDiamond@ns.sympatico.ca> writes:

    A long, long time ago I started using a function (John Wiegley's
    auto-correct function) which, up until Emacs 28, worked by defining a
    function to maybe correct a word, and then
    (add-hook 'pre-abbrev-expand-hook 'fix-transposed-characters)

    I now find out that pre-abbrev-expand-hook was obsoleted quite some time
    ago, but it worked until I upgraded to emacs 28.2, and so I never noticed
    this obsoletion until now.

    I still want to use this function, but it isn't clear to me how to use it. >> I tried
    (add-hook 'abbrev-expand-functions 'fix-transposed-characters)
    but I was then rewarded with

    Hi,

    It seems that your 'fix-transposed-characters' function does not require
    any arguments and it might not be the case for functions in 'abbrev-expand-functions'.

    Anyway, there is other obsolescence going on ('abbrev-expand-functions'
    for example). So I think the new way of doing what you are trying to
    achieve is the following:

    (advice-add abbrev-expand-function :before (lambda () (message "foo")))

    The before lambda has no arguments so maybe you could replace it by 'fix-transposed-charactersrCa but I don't understand what 'fix-transposed-characters' is doing, if the context will be what's
    needed, etc. So try at your own risk.

    Manuel,

    thanks 1E6. Using

    (advice-add abbrev-expand-function
    :before (lambda () (fix-transposed-characters)))

    worked perfectly. I guess I need to get up to speed on adding advice.

    Jim
    --- Synchronet 3.21d-Linux NewsLink 1.2