unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Masatake YAMATO <jet@gyve.org>
Subject: Using overlay in register
Date: Thu, 18 Mar 2004 19:33:46 +0900 (JST)	[thread overview]
Message-ID: <20040318.193346.21592706.jet@gyve.org> (raw)

How do you think using overlay instead of marker to represent a point in register.el?

The advantage is strong visual feed back. During editing emacs,
sometime I forget the position of a register. With overlay, we can put
a face on the position. The faces let me keep the memory about the
position of registers. We can also put help-echo on the overlay.

BTW, (overlay-start overlay) < (overlay-end overlay) is guaranteed?

Masatake YAMATO

2004-03-18  Masatake YAMATO  <jet@gyve.org>

	* register.el (register): New customize group.
	(register-point): New face.
	(register-alist): Doc fix.
	(set-register): Delete overlay before
	setting new value to the register.
	(register-put-overlay-at-point): New function.
	(register-get-overlay-position): New function.
	(point-to-register): Use overlay instead of marker.
	(jump-to-register): Ditto.
	(describe-register-1): Ditto.
	(insert-register): Ditto.
	(register-swap-out): Ditto. Doc fix.

cvs diff: warning: unrecognized response `access control disabled, clients can connect from any host' from cvs server
Index: lisp/register.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/register.el,v
retrieving revision 1.48
diff -u -r1.48 register.el
--- lisp/register.el	16 Mar 2004 09:52:36 -0000	1.48
+++ lisp/register.el	18 Mar 2004 10:20:36 -0000
@@ -31,9 +31,20 @@
 
 ;;; Code:
 
+(defgroup register ()
+  "register commands for Emacs."
+  :group 'editing
+  :prefix "register-")
+
+(defface register-point
+  '((((class color)) (:box "blue"))
+    (t (:underline t)))
+  "Face for the overlay associated with register."
+  :group 'register)
+
 (defvar register-alist nil
   "Alist of elements (NAME . CONTENTS), one for each Emacs register.
-NAME is a character (a number).  CONTENTS is a string, number, marker or list.
+NAME is a character (a number).  CONTENTS is a string, number, overlay or list.
 A list of strings represents a rectangle.
 A list of the form (file . NAME) represents the file named NAME.
 A list of the form (file-query NAME POSITION) represents position POSITION
@@ -50,23 +61,46 @@
 (defun set-register (register value)
   "Set contents of Emacs register named REGISTER to VALUE.  Returns VALUE.
 See the documentation of the variable `register-alist' for possible VALUE."
+  ;; If the old value is overlay, delete it first.
+  (let ((overlay (get-register register)))
+    (if (overlayp overlay)
+	(delete-overlay overlay)))
   (let ((aelt (assq register register-alist)))
     (if aelt
 	(setcdr aelt value)
       (push (cons register value) register-alist))
     value))
 
+(defun register-put-overlay-at-point (register)
+  "Put a overlay associated with REGISTER at the point."
+  (let ((overlay (make-overlay (point) 
+			       (1+ (point))
+			       (current-buffer)
+			       t))
+	(help (format "Register: %s\nType \"%s %s\" to jump here." 
+		      (single-key-description register)
+		      (substitute-command-keys "\\[jump-to-register]")
+		      (single-key-description register))))
+    (overlay-put overlay 'face 'register-point)
+    (overlay-put overlay 'help-echo help)
+    (overlay-put overlay 'register register)
+    overlay))
+
+(defun register-get-overlay-position (overlay)
+  "Get the position for OVERLAY."
+  (min (overlay-start overlay) (overlay-end overlay)))
+ 
 (defun point-to-register (register &optional arg)
   "Store current location of point in register REGISTER.
 With prefix argument, store current frame configuration.
 Use \\[jump-to-register] to go to that location or restore that configuration.
 Argument is a character, naming the register."
   (interactive "cPoint to register: \nP")
-  ;; Turn the marker into a file-ref if the buffer is killed.
+  ;; Turn the overlay into a file-ref if the buffer is killed.
   (add-hook 'kill-buffer-hook 'register-swap-out nil t)
   (set-register register
 		(if arg (list (current-frame-configuration) (point-marker))
-		  (point-marker))))
+		  (register-put-overlay-at-point register))))
 
 (defun window-configuration-to-register (register &optional arg)
   "Store the window configuration of the selected frame in register REGISTER.
@@ -106,11 +140,11 @@
      ((and (consp val) (window-configuration-p (car val)))
       (set-window-configuration (car val))
       (goto-char (cadr val)))
-     ((markerp val)
-      (or (marker-buffer val)
+     ((overlayp val)
+      (or (overlay-buffer val)
 	  (error "That register's buffer no longer exists"))
-      (switch-to-buffer (marker-buffer val))
-      (goto-char val))
+      (switch-to-buffer (overlay-buffer val))
+      (goto-char (register-get-overlay-position val)))
      ((and (consp val) (eq (car val) 'file))
       (find-file (cdr val)))
      ((and (consp val) (eq (car val) 'file-query))
@@ -123,15 +157,15 @@
       (error "Register doesn't contain a buffer position or configuration")))))
 
 (defun register-swap-out ()
-  "Turn markers into file-query references when a buffer is killed."
+  "Turn overlays into file-query references when a buffer is killed."
   (and buffer-file-name
        (dolist (elem register-alist)
-	 (and (markerp (cdr elem))
-	      (eq (marker-buffer (cdr elem)) (current-buffer))
+	 (and (overlayp (cdr elem))
+	      (eq (overlay-buffer (cdr elem)) (current-buffer))
 	      (setcdr elem
 		      (list 'file-query
 			    buffer-file-name
-			    (marker-position (cdr elem))))))))
+			    (overlay-start (cdr elem))))))))
 
 (defun number-to-register (number register)
   "Store a number in a register.
@@ -187,14 +221,14 @@
      ((numberp val)
       (princ val))
 
-     ((markerp val)
-      (let ((buf (marker-buffer val)))
+     ((overlayp val)
+      (let ((buf (overlay-buffer val)))
 	(if (null buf)
-	    (princ "a marker in no buffer")
+	    (princ "a overlay in no buffer")
 	  (princ "a buffer position:\n    buffer ")
 	  (princ (buffer-name buf))
 	  (princ ", position ")
-	  (princ (marker-position val)))))
+	  (princ (register-get-overlay-position val)))))
 
      ((and (consp val) (window-configuration-p (car val)))
       (princ "a window configuration."))
@@ -264,8 +298,8 @@
       (insert-for-yank val))
      ((numberp val)
       (princ val (current-buffer)))
-     ((and (markerp val) (marker-position val))
-      (princ (marker-position val) (current-buffer)))
+     ((and (overlayp val) (overlay-start val))
+      (princ (register-get-overlay-position val) (current-buffer)))
      (t
       (error "Register does not contain text"))))
   (if (not arg) (exchange-point-and-mark)))

             reply	other threads:[~2004-03-18 10:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-18 10:33 Masatake YAMATO [this message]
2004-03-20  4:49 ` Using overlay in register Richard Stallman
2004-03-21 14:03   ` Masatake YAMATO
2004-03-22  5:24     ` Richard Stallman
2004-03-22  5:24     ` Richard Stallman
2004-03-22  8:00       ` overlay-start > overlay-end Masatake YAMATO
2004-03-23  3:04         ` Richard Stallman
2004-03-23  8:45           ` Masatake YAMATO
2004-03-23 14:18             ` Stefan Monnier
2004-03-24  5:34             ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040318.193346.21592706.jet@gyve.org \
    --to=jet@gyve.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).