[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mark a position
From: |
Markus Wawryniuk |
Subject: |
Re: Mark a position |
Date: |
Thu, 15 Feb 2001 08:59:52 +0100 |
Hi,
you should read the book
Writing GNU Emacs Extensions
Editor Customizations and Creations with Lisp
By Bob Glickstein
O'Reilly
The unscroll example (3rd chapter) should solve your problem. You can
scroll with C-v, M-v and other commands through the text and recover the
original cursor position with the function unscroll.
Here is the code from my .emacs.
;;; unscroll
(defvar unscroll-point (make-marker)
"Cursor position for next call to 'unscroll'.")
(defvar unscroll-window-start (make-marker)
"Window start for next call to 'unscroll'.")
(defvar unscroll-hscroll nil
"Hscroll for next call to 'unscroll'.")
(defun unscroll-maybe-remember ()
(if (not (get last-command 'unscrollable))
(progn
(set-marker unscroll-point (point))
(set-marker unscroll-window-start (window-start))
(setq unscroll-hscroll (window-hscroll)))))
(defadvice scroll-up (before remember-for-unscroll activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-down (before remember-for-unscroll activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-left (before remember-for-unscroll activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-right (before remember-for-unscroll activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-one-lines-ahead (before remember-for-unscroll activate
compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-one-lines-behind (before remember-for-unscroll
activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-n-lines-ahead (before remember-for-unscroll activate
compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-n-lines-behind (before remember-for-unscroll activate
compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice beginning-of-buffer (before remember-for-unscroll activate
compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice end-of-buffer (before remember-for-unscroll activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(if running-under-xemacs
(progn
(defadvice scroll-up-command (before remember-for-unscroll
activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(defadvice scroll-down-command (before remember-for-unscroll
activate compile)
"Remember where we started from, for 'unscroll'."
(unscroll-maybe-remember))
(put 'scroll-up-command 'unscrollable t)
(put 'scroll-down-command 'unscrollable t)))
(put 'scroll-up 'unscrollable t)
(put 'scroll-down 'unscrollable t)
(put 'scroll-right 'unscrollable t)
(put 'scroll-left 'unscrollable t)
(put 'scroll-one-lines-ahead 'unscrollable t)
(put 'scroll-one-lines-behind 'unscrollable t)
(put 'scroll-n-lines-ahead 'unscrollable t)
(put 'scroll-n-lines-behind 'unscrollable t)
(put 'beginning-of-buffer 'unscrollable t)
(put 'end-of-buffer 'unscrollable t)
(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))
(global-set-key "\C-c\C-j" 'unscroll)
Have luck!
Markus
Alexandre Brillant wrote:
> Thank you for responses about TAGS.
>
> Another question : Can I save the current position of the cursor and
> retreive it later easily ? I mean I need
> sometimes to look at a particular part of a document and retrieive
> quickly the original position, knowing that
> I don't want to open a new buffer.
>
> If I can save in memory a cursor position, is there a way to store
> several position with a kind of flag system ?
>
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-gnu-emacs