help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: show registered positions


From: rgb
Subject: Re: show registered positions
Date: 18 Oct 2005 14:08:55 -0700
User-agent: G2/0.2

rgb wrote:
> Peter Tury wrote:
> > Hi,
> >
> > I see in the manual (GNU Emacs 21.3.1 on Win XP; I may switch to using CVS)
> > that C-x r <SPC> R saves position of point in register R.
> >
> > Is it possible somehow easily (=using at most a few elisp lines in .emacs?)
> > to mark those lines (may be: highlight?) what contain saved positions, e.g.
> > at the left edge of the buffer? Or at least list all registers what contain
> > a position?
> >
> > I mean that in the case I have several saved positions, it would be nice to
> > see them in (pick them from?) a list; or see them when I am around a
> > "saved" line...
>
> There is list-registers and view-registers and the contents of
> register-alist are fairly well documented if you use C-h v.
>
> I'm not sure if that helps but I can't remember seeing a package
> that acutally marks the locations.  You could probably redefine
> set-register to add an overlay whenever a point is put into
> a register and remove the overlay when the register's value is
> changed.  It doesn't look like it would be too hard.

I got to thinking how nice it would be to have what you described.
This is a total hack but it seems to do ok.  Floating your mouse
over the highlighted character should tell you which register.
I noticed just before posting that markers in files don't
restore the overlay when the file is re-visited.  But I never
really re-visit files that way anyhow....
Maybe somebody would like to run with this some more?

(defface register-marker-face '((t (:background "grey")))
  "Used to mark register positions in a buffer."
  :group 'faces)

;; this redefines (and therefore overrides) the standard function
;; of the same name.  Yea, maybe advice would have been better but
;; I was lazy.
(defun set-register (register value)
  "Set Emacs register named REGISTER to VALUE.  Returns VALUE.
See the documentation of `register-alist' for possible VALUE."
  (let ((aelt (assq register register-alist))
        (sovl (intern (concat "point-register-overlay-"
                              (char-to-string register))))
       )
    (when (not (boundp sovl))
      (set sovl (make-overlay (point)(point)))
      (overlay-put (symbol-value sovl) 'face 'register-marker-face)
      (overlay-put (symbol-value sovl) 'help-echo
                   (concat "Register: `"
                           (char-to-string register) "'")))
    (delete-overlay (symbol-value sovl))
    (if (markerp value)
        (move-overlay (symbol-value sovl) value (1+ value)))
    (if aelt
        (setcdr aelt value)
      (push (cons register value) register-alist))
    value))



reply via email to

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