[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on troubleshooting function to "unscroll"

From: Will Monroe
Subject: Re: Advice on troubleshooting function to "unscroll"
Date: Sun, 25 Jan 2015 15:57:41 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0


Thank you for you response!

On 01/25/2015 03:35 PM, Joost Kremers wrote:
Will Monroe wrote:
(defadvice scroll-up (before remember-for-unscroll
                             activate compile)
    "Remember where we started from, for 'unscroll'."
    (if (not (eq last-command 'scroll-up))

Note that

     (if (not <some-test>)
          ... )

can be written as

     (unless <some-test>

if you don't have an `else' part. It's slightly more readable that way

Thanks for recommending that more-readable rewrite. I will look into redrafting it this way.

Also, as of (I think) Emacs 24.4, defadvice is no longer the recommended
way to advise functions. There's a new package (`nadvice.el`) that
defines `advice-add`. See the Elisp manual, section "Advising functions".


Thank you again. This is also very helpful. I found that defadvice still worked for this example (with one change, see below) but I won't likely use it again since it's no longer preferred.

The test was just opening a lengthy file, usually an info page or an
existing org-mode file, pressing C-v a few times, and then using M-x
unscroll.  In all cases, I found that M-x unscroll would return to the
position just before the last C-v but not to the original position.  In
other words, if I pressed C-v two times and then pressed M-x unscroll,
in would only go back one C-v.  My intent, and that of the example in
the book, is to return the point the position before any C-v key
sequences were pressed.

Have you checked what `C-v` is bound to? In my Emacs (24.4) it's bound
to `scroll-up-command`, not to `scroll-up`. So that would defeat your if
test above.

So simple! Thank you for this insight. Going forward, I'll include a check of what functions my keybindings are actually bound to! After substituting scroll-up-command for scroll-up in two places, it worked as intended.

Thank you very much,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]