emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r104727: Extend emacs register to acc


From: Leo Liu
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104727: Extend emacs register to accept value from registerv-make
Date: Sun, 26 Jun 2011 14:37:04 +0800
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104727
committer: Leo Liu <address@hidden>
branch nick: trunk
timestamp: Sun 2011-06-26 14:37:04 +0800
message:
  Extend emacs register to accept value from registerv-make
  
  A value object returned by `registerv-make' has slots to control
  jump-to-register, describe-register-1 and insert-register.
modified:
  lisp/ChangeLog
  lisp/register.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-26 04:05:39 +0000
+++ b/lisp/ChangeLog    2011-06-26 06:37:04 +0000
@@ -1,3 +1,11 @@
+2011-06-26  Leo Liu  <address@hidden>
+
+       * register.el (registerv): New struct.
+       (registerv-make): New function.
+       (jump-to-register, describe-register-1, insert-register): Support
+       the jump-func, print-func and insert-func slot of a registerv
+       struct.  (Bug#8415)
+
 2011-06-26  Chong Yidong  <address@hidden>
 
        * vc/vc.el (vc-revert-show-diff): New defcustom.

=== modified file 'lisp/register.el'
--- a/lisp/register.el  2011-04-19 13:44:55 +0000
+++ b/lisp/register.el  2011-06-26 06:37:04 +0000
@@ -28,6 +28,8 @@
 ;; pieces of buffer state to named variables.  The entry points are
 ;; documented in the Emacs user's manual.
 
+(eval-when-compile (require 'cl))
+
 (declare-function semantic-insert-foreign-tag "semantic/tag" (foreign-tag))
 (declare-function semantic-tag-buffer "semantic/tag" (tag))
 (declare-function semantic-tag-start "semantic/tag" (tag))
@@ -50,9 +52,36 @@
 
 ;;; Code:
 
+(defstruct
+  (registerv (:constructor nil)
+            (:constructor registerv--make (&optional data print-func
+                                                     jump-func insert-func))
+            (:copier nil)
+            (:type vector)
+            :named)
+  (data        nil :read-only t)
+  (print-func  nil :read-only t)
+  (jump-func   nil :read-only t)
+  (insert-func nil :read-only t))
+
+(defun* registerv-make (data &key print-func jump-func insert-func)
+  "Create a register value object.
+
+DATA can be any value.
+PRINT-FUNC if provided controls how `list-registers' and
+`view-register' print the register.  It should be a function
+recieving one argument DATA and print text that completes
+this sentence:
+  Register X contains [TEXT PRINTED BY PRINT-FUNC]
+JUMP-FUNC if provided, controls how `jump-to-register' jumps to the register.
+INSERT-FUNC if provided, controls how `insert-register' insert the register.
+They both receive DATA as argument."
+  (registerv--make data print-func jump-func insert-func))
+
 (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, marker, list
+or a struct returned by `registerv-make'.
 A list of strings represents a rectangle.
 A list of the form (file . FILE-NAME) represents the file named FILE-NAME.
 A list of the form (file-query FILE-NAME POSITION) represents
@@ -120,6 +149,11 @@
   (interactive "cJump to register: \nP")
   (let ((val (get-register register)))
     (cond
+     ((registerv-p val)
+      (assert (registerv-jump-func val) nil
+              "Don't know how to jump to register %s"
+              (single-key-description register))
+      (funcall (registerv-jump-func val) (registerv-data val)))
      ((and (consp val) (frame-configuration-p (car val)))
       (set-frame-configuration (car val) (not delete))
       (goto-char (cadr val)))
@@ -209,6 +243,11 @@
   (princ " contains ")
   (let ((val (get-register register)))
     (cond
+     ((registerv-p val)
+      (if (registerv-print-func val)
+          (funcall (registerv-print-func val) (registerv-data val))
+        (princ "[UNPRINTABLE CONTENTS].")))
+
      ((numberp val)
       (princ val))
 
@@ -285,8 +324,11 @@
   (push-mark)
   (let ((val (get-register register)))
     (cond
-     ((consp val)
-      (insert-rectangle val))
+     ((registerv-p val)
+      (assert (registerv-insert-func val) nil
+              "Don't know how to insert register %s"
+              (single-key-description register))
+      (funcall (registerv-insert-func val) (registerv-data val)))
      ((stringp val)
       (insert-for-yank val))
      ((numberp val)


reply via email to

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