unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Advice on troubleshooting function to "unscroll"
@ 2015-01-25 20:52 Will Monroe
  2015-01-25 21:35 ` Marcin Borkowski
  2015-01-25 21:45 ` Marcin Borkowski
  0 siblings, 2 replies; 19+ messages in thread
From: Will Monroe @ 2015-01-25 20:52 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I'm studying Emacs Lisp so that I can become more proficient at 
customizing GNU Emacs for purposes, mainly using org-mode.  I'm studying 
alone using Bob Glickstein's *Writing GNU Emacs Extensions*.  So far, 
the book has been a terrific guide to basic concepts.  But I've run into 
a problem that I can't seem to troubleshoot any further and I'd 
appreciate advice on: 1) the best way to troubleshoot this problem 
(e.g., other forums, listservs, or IRC channels that might be more 
appropriate) and 2) troubleshooting the problem itself.  I apologize in 
advance if this query has failed to take into account any basics or if 
it would be better posed elsewhere.  I welcome your on the best way to 
proceed.

So, following Glickstein's advice in Chapter 3, I'm trying to create a 
function that will allow me to create an "unscroll" function that will 
allow me to return to a prior buffer position after (inadvertently) 
pressing C-v a few times.  The code to do this defines three new 
variables, defines advice for an extant Emacs function, scroll-up, and 
then defines a new function, unscroll.  The code is below.

#+BEGIN_SRC emacs-lisp
(defvar unscroll-point nil
   "Cursor position for next call to 'unscroll'.")

(defvar unscroll-window-start nil
   "Window start for next call to 'unscroll'.")

(defvar unscroll-hscroll nil
   "Hscroll start for next call to 'unscroll'.")

(defadvice scroll-up (before remember-for-unscroll
			     activate compile)
   "Remember where we started from, for 'unscroll'."
   (if (not (eq last-command 'scroll-up))
       (setq unscroll-point (point)
	      unscroll-window-start (window-start)
	      unscroll-hscroll (window-hscroll))))

(defun unscroll ()
   "Revert to 'unscroll-point' and 'unscroll-window-start'."
   (interactive)
   (goto-char unscroll-point)
   (set-window-start nil unscroll-window-start)
   (set-window-hscroll nil unscroll-hscroll))
#+END_SRC

I've loaded this code in Emacs under two different conditions:  1) by 
firing up a vanilla Emacs instance without any configuration file, and 
evaluating the code in scratch and 2) by saving the above code as the 
sole contents in a configuration file (~/.emacs.d/init.el) and then 
starting up Emacs.  I've done this on two different machines both 
running versions of Emacs 24.

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.

I could move one but I suspect that the mistake I've made will come up 
again.  I'd really welcome your (gentle) feedback!

All the best,

Will



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-01-26  1:33 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.18583.1422219396.1147.help-gnu-emacs@gnu.org>
2015-01-25 21:35 ` Advice on troubleshooting function to "unscroll" Joost Kremers
2015-01-25 21:57   ` Will Monroe
2015-01-25 20:52 Will Monroe
2015-01-25 21:35 ` Marcin Borkowski
2015-01-25 21:43   ` Will Monroe
2015-01-25 21:55     ` Marcin Borkowski
2015-01-25 22:01       ` Will Monroe
2015-01-25 21:45 ` Marcin Borkowski
2015-01-25 22:03   ` Will Monroe
2015-01-25 22:09     ` Marcin Borkowski
2015-01-25 22:45     ` Drew Adams
2015-01-25 22:56       ` Will Monroe
2015-01-25 23:15         ` Marcin Borkowski
2015-01-26  0:03         ` Drew Adams
2015-01-26  0:16           ` Marcin Borkowski
2015-01-26  1:06             ` Drew Adams
2015-01-26  1:17             ` Will Monroe
2015-01-26  1:21               ` Marcin Borkowski
2015-01-26  1:33               ` Drew Adams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).