From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#8415: 23.3.50; Extensible Emacs Registers Date: Mon, 04 Apr 2011 18:19:12 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1301956657 8251 80.91.229.12 (4 Apr 2011 22:37:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 4 Apr 2011 22:37:37 +0000 (UTC) Cc: Davis Herring , 8415@debbugs.gnu.org, Daniel Colascione To: Leo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 05 00:37:32 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q6sOo-0002V9-Rd for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Apr 2011 00:37:32 +0200 Original-Received: from localhost ([127.0.0.1]:48283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6sOn-0007Ll-TS for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 Apr 2011 18:37:29 -0400 Original-Received: from [140.186.70.92] (port=39290 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6sOb-0007ER-HV for bug-gnu-emacs@gnu.org; Mon, 04 Apr 2011 18:37:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6sOa-0004Xi-1i for bug-gnu-emacs@gnu.org; Mon, 04 Apr 2011 18:37:17 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q6sOZ-0004Xc-W1 for bug-gnu-emacs@gnu.org; Mon, 04 Apr 2011 18:37:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q6s7v-0005gX-0w; Mon, 04 Apr 2011 18:20:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Apr 2011 22:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8415 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 8415-submit@debbugs.gnu.org id=B8415.130195556521802 (code B ref 8415); Mon, 04 Apr 2011 22:20:02 +0000 Original-Received: (at 8415) by debbugs.gnu.org; 4 Apr 2011 22:19:25 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q6s7J-0005fa-7K for submit@debbugs.gnu.org; Mon, 04 Apr 2011 18:19:25 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183] helo=ironport2-out.pppoe.ca) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q6s7H-0005fP-Qz for 8415@debbugs.gnu.org; Mon, 04 Apr 2011 18:19:24 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAHhDmk1Ld/Y6/2dsb2JhbAClY3iIeboShWsElj8 X-IronPort-AV: E=Sophos;i="4.63,299,1299474000"; d="scan'208";a="103160661" Original-Received: from 75-119-246-58.dsl.teksavvy.com (HELO pastel.home) ([75.119.246.58]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 04 Apr 2011 18:19:13 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id F1F6858C5B; Mon, 4 Apr 2011 18:19:12 -0400 (EDT) In-Reply-To: (Leo's message of "Tue, 05 Apr 2011 01:37:07 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 04 Apr 2011 18:20:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45632 Archived-At: >> A more backward-compatible change would be to not use register-structs >> for pre-existing cases (i.e. markers, strings, lists of string, and >> win-confs). I.e. only add register structs as a new accepted kind >> of value (and move `name' out of the struct). >> The patch would most likely be a lot smaller. > The original register.el is very inflexible and does its work mostly by > guess because it misses the best moment to decide how to > jump/insert/print a register i.e. at the time of creating it. AFAICT, the code currently doesn't guess: the different kinds of values are mutually exclusive. So the moment at which they decide which code to use doesn't matter because it'll give the same answer (tho as you point out there are errors in this code currently because it's dispersed). > So we will have to make almost all values a struct anyway to fix bugs > like this. Yes, all new types will use register structs. That's not a problem. And you can even later-on de-support old types and have them go through register structs as well. > As I said in another post, subsequent to this patch I will break down > jump-to-register, describe-register-1, insert-register to take advantage > of this new implementation. That's good. But I'd rather you break backward compatibility at *that* point rather than right from the start. I.e. start with a patch like the one below. Of course, instead of register structs, you can use functions (like we do for completion tables) as in: === modified file 'lisp/register.el' --- lisp/register.el 2011-01-25 04:08:28 +0000 +++ lisp/register.el 2011-04-04 22:16:56 +0000 @@ -52,7 +52,10 @@ (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 can take various forms: +A function that takes one argument (the action to perform). + The action can be `print', `insert', or `jump'. Any action it does not + understand should result in signalling an error. 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 +123,7 @@ (interactive "cJump to register: \nP") (let ((val (get-register register))) (cond + ((functionp val) (funcall val 'jump)) ((and (consp val) (frame-configuration-p (car val))) (set-frame-configuration (car val) (not delete)) (goto-char (cadr val))) @@ -209,6 +213,7 @@ (princ " contains ") (let ((val (get-register register))) (cond + ((functionp val) (funcall val 'print)) ((numberp val) (princ val)) @@ -285,6 +290,7 @@ (push-mark) (let ((val (get-register register))) (cond + ((functionp val) (funcall val 'insert)) ((consp val) (insert-rectangle val)) ((stringp val) -- Stefan === modified file 'lisp/register.el' --- lisp/register.el 2011-01-25 04:08:28 +0000 +++ lisp/register.el 2011-04-04 22:10:11 +0000 @@ -52,7 +52,8 @@ (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 can take various forms: +A `register' structure, made with `register-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 @@ -63,6 +64,18 @@ A list of the form (FRAME-CONFIGURATION POSITION) represents a saved frame configuration plus a saved value of point.") +(eval-when-compile (require 'cl)) + +(defstruct + (register (:constructor nil) + (:constructor register-make (value &key print-func + jump-func insert-func)) + (:copier nil)) + (value nil :read-only t) + (print-func nil :read-only t) + (jump-func nil :read-only t) + (insert-func nil :read-only t)) + (defun get-register (register) "Return contents of Emacs register named REGISTER, or nil if none." (cdr (assq register register-alist))) @@ -120,6 +133,7 @@ (interactive "cJump to register: \nP") (let ((val (get-register register))) (cond + ((register-p val) (funcall (register-jump-func val) val)) ((and (consp val) (frame-configuration-p (car val))) (set-frame-configuration (car val) (not delete)) (goto-char (cadr val))) @@ -149,6 +163,7 @@ (defun register-swap-out () "Turn markers into file-query references when a buffer is killed." + ;; FIXME: Let register structures hook here as well. (and buffer-file-name (dolist (elem register-alist) (and (markerp (cdr elem)) @@ -177,6 +192,7 @@ (defun increment-register (number register) "Add NUMBER to the contents of register REGISTER. Interactively, NUMBER is the prefix arg." + ;; FIXME: Let register structures hook here as well. (interactive "p\ncIncrement register: ") (or (numberp (get-register register)) (error "Register does not contain a number")) @@ -209,6 +225,7 @@ (princ " contains ") (let ((val (get-register register))) (cond + ((register-p val) (funcall (register-print-func val) val)) ((numberp val) (princ val)) @@ -285,6 +302,7 @@ (push-mark) (let ((val (get-register register))) (cond + ((register-p val) (funcall (register-insert-func val) val)) ((consp val) (insert-rectangle val)) ((stringp val) @@ -315,6 +333,7 @@ With prefix arg, delete as well. Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. START and END are buffer positions indicating what to append." + ;; FIXME: Let register structures hook here as well? (interactive "cAppend to register: \nr\nP") (let ((reg (get-register register)) (text (filter-buffer-substring start end))) @@ -329,6 +348,7 @@ With prefix arg, delete as well. Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. START and END are buffer positions indicating what to prepend." + ;; FIXME: Let register structures hook here as well? (interactive "cPrepend to register: \nr\nP") (let ((reg (get-register register)) (text (filter-buffer-substring start end)))