From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Chong Yidong" Newsgroups: gmane.emacs.devel Subject: buffer-substring-filter Date: 14 Mar 2005 04:55:45 -0800 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1110805215 26026 80.91.229.2 (14 Mar 2005 13:00:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 14 Mar 2005 13:00:15 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 14 14:00:14 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DApAw-0006IW-NP for ged-emacs-devel@m.gmane.org; Mon, 14 Mar 2005 14:00:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DApQc-00018d-V2 for ged-emacs-devel@m.gmane.org; Mon, 14 Mar 2005 08:16:15 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DApQ0-0000xF-Lg for emacs-devel@gnu.org; Mon, 14 Mar 2005 08:15:36 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DApPy-0000wZ-Lk for emacs-devel@gnu.org; Mon, 14 Mar 2005 08:15:36 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DApPy-0000w2-FG for emacs-devel@gnu.org; Mon, 14 Mar 2005 08:15:34 -0500 Original-Received: from [171.67.16.123] (helo=smtp1.Stanford.EDU) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DAp6w-0008QK-JL; Mon, 14 Mar 2005 07:55:55 -0500 Original-Received: from physics.stanford.edu (physics.Stanford.EDU [171.64.107.180]) by smtp1.Stanford.EDU (8.12.11/8.12.11) with ESMTP id j2ECtmu8023413; Mon, 14 Mar 2005 04:55:48 -0800 Original-Received: from physics.stanford.edu (localhost.localdomain [127.0.0.1]) by physics.stanford.edu (8.12.8/8.12.5) with ESMTP id j2ECtkho024629; Mon, 14 Mar 2005 04:55:47 -0800 Original-Received: (from cyd@localhost) by physics.stanford.edu (8.12.8/8.12.8/Submit) id j2ECtkEb024625; Mon, 14 Mar 2005 04:55:46 -0800 Original-To: rms@gnu.org, emacs-devel@gnu.org Original-Lines: 134 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: news.gmane.org gmane.emacs.devel:34571 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34571 This patch implements the kill filter following RMS' suggestions, as a variant of buffer-substring. Is it OK? *** emacs/lisp/simple.el~ Mon Mar 14 20:50:53 2005 --- emacs/lisp/simple.el Mon Mar 14 20:53:37 2005 *************** *** 2215,2220 **** --- 2215,2251 ---- (reset-this-command-lengths) (restore-overriding-map)) + (defvar buffer-substring-filters nil + "List of filter functions for `filter-buffer-substring'. + Each function must accept a single argument, a string, and return + a string. The buffer substring is passed to the first function + in the list, and the return value of each function is passed to + the next. The return value of the last function is used as the + return value of `filter-buffer-substring'. + + If this variable is nil, no filtering is performed.") + + (defun filter-buffer-substring (beg end &optional delete) + "Return the buffer substring between BEG and END, after filtering. + The buffer substring is passed through each of the filter + functions in `buffer-substring-filters', and the value from the + last filter function is returned. If `buffer-substring-filters' + is nil, the buffer substring is returned unaltered. + + If DELETE is non-nil, the text between BEG and END is deleted + from the buffer. + + This function should be used instead of `buffer-substring' or + `delete-and-extract-region' when you want to allow filtering to + take place. For example, major or minor modes can use + `buffer-substring-filters' to extract characters that are special + to a buffer, and should not be copied into other buffers." + (let ((string (if delete (delete-and-extract-region beg end) + (buffer-substring beg end)))) + (mapcar (lambda (filter) (setq string (funcall filter string))) + buffer-substring-filters) + string)) + ;;;; Window system cut and paste hooks. (defvar interprogram-cut-function nil *************** *** 2391,2397 **** text. See `insert-for-yank'." (interactive "r") (condition-case nil ! (let ((string (delete-and-extract-region beg end))) (when string ;STRING is nil if BEG = END ;; Add that string to the kill ring, one way or another. (if (eq last-command 'kill-region) --- 2422,2428 ---- text. See `insert-for-yank'." (interactive "r") (condition-case nil ! (let ((string (filter-buffer-substring beg end t))) (when string ;STRING is nil if BEG = END ;; Add that string to the kill ring, one way or another. (if (eq last-command 'kill-region) *************** *** 2427,2434 **** system cut and paste." (interactive "r") (if (eq last-command 'kill-region) ! (kill-append (buffer-substring beg end) (< end beg)) ! (kill-new (buffer-substring beg end))) (if transient-mark-mode (setq deactivate-mark t)) nil) --- 2458,2465 ---- system cut and paste." (interactive "r") (if (eq last-command 'kill-region) ! (kill-append (filter-buffer-substring beg end) (< end beg)) ! (kill-new (filter-buffer-substring beg end))) (if transient-mark-mode (setq deactivate-mark t)) nil) *** emacs/lisp/register.el~ Mon Mar 14 20:45:35 2005 --- emacs/lisp/register.el Mon Mar 14 20:46:25 2005 *************** *** 277,283 **** Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. START and END are buffer positions indicating what to copy." (interactive "cCopy to register: \nr\nP") ! (set-register register (buffer-substring start end)) (if delete-flag (delete-region start end))) (defun append-to-register (register start end &optional delete-flag) --- 277,283 ---- Called from program, takes four args: REGISTER, START, END and DELETE-FLAG. START and END are buffer positions indicating what to copy." (interactive "cCopy to register: \nr\nP") ! (set-register register (filter-buffer-substring start end)) (if delete-flag (delete-region start end))) (defun append-to-register (register start end &optional delete-flag) *************** *** 289,295 **** (or (stringp (get-register register)) (error "Register does not contain text")) (set-register register (concat (get-register register) ! (buffer-substring start end))) (if delete-flag (delete-region start end))) (defun prepend-to-register (register start end &optional delete-flag) --- 289,295 ---- (or (stringp (get-register register)) (error "Register does not contain text")) (set-register register (concat (get-register register) ! (filter-buffer-substring start end))) (if delete-flag (delete-region start end))) (defun prepend-to-register (register start end &optional delete-flag) *************** *** 300,306 **** (interactive "cPrepend to register: \nr\nP") (or (stringp (get-register register)) (error "Register does not contain text")) ! (set-register register (concat (buffer-substring start end) (get-register register))) (if delete-flag (delete-region start end))) --- 300,306 ---- (interactive "cPrepend to register: \nr\nP") (or (stringp (get-register register)) (error "Register does not contain text")) ! (set-register register (concat (filter-buffer-substring start end) (get-register register))) (if delete-flag (delete-region start end)))