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: Re: buffer-substring-filter Date: Wed, 16 Mar 2005 17:49:24 -0500 (EST) Message-ID: <1411.220.255.169.59.1111013364.squirrel@220.255.169.59> References: <33102.203.116.59.24.1110846598.squirrel@203.116.59.24> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1111013543 3974 80.91.229.2 (16 Mar 2005 22:52:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 16 Mar 2005 22:52:23 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 16 23:52:22 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DBhLk-00085J-Ot for ged-emacs-devel@m.gmane.org; Wed, 16 Mar 2005 23:50:52 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DBhaC-0002KC-Mw for ged-emacs-devel@m.gmane.org; Wed, 16 Mar 2005 18:05:44 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DBhZg-0002Dn-SU for emacs-devel@gnu.org; Wed, 16 Mar 2005 18:05:13 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DBhZc-0002Bp-70 for emacs-devel@gnu.org; Wed, 16 Mar 2005 18:05:08 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DBhZb-0002Ba-Ng for emacs-devel@gnu.org; Wed, 16 Mar 2005 18:05:07 -0500 Original-Received: from [64.21.80.18] (helo=shark.dnsvelocity.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1DBhKb-0007wy-GK; Wed, 16 Mar 2005 17:49:37 -0500 Original-Received: from stupidch by shark.dnsvelocity.com with local (Exim 4.44) id 1DBhKO-0002vV-77; Wed, 16 Mar 2005 17:49:24 -0500 Original-Received: from 220.255.169.59 ([220.255.169.59]) (SquirrelMail authenticated user cyd@stupidchicken.com); by www.stupidchicken.com with HTTP; Wed, 16 Mar 2005 17:49:24 -0500 (EST) In-Reply-To: Original-To: rms@gnu.org User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a X-Priority: 3 (Normal) Importance: Normal X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - shark.dnsvelocity.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [32675 33085] / [47 12] X-AntiAbuse: Sender Address Domain - stupidchicken.com X-Source: /usr/local/cpanel/3rdparty/bin/php X-Source-Args: /usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/base/3rdparty/squirrelmail/src/compose.php X-Source-Dir: :/base/3rdparty/squirrelmail/src 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:34648 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34648 > In that case, could you make those two little changes, and then > would someone please install it? Here is the revised patch. *** emacs/lisp/simple.el~ Thu Mar 17 06:46:12 2005 --- emacs/lisp/simple.el Thu Mar 17 06:52:25 2005 *************** *** 2215,2220 **** --- 2215,2256 ---- (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. + + Point is temporarily set to BEG before caling + `buffer-substring-filters', in case the functions need to know + where the text came from. + + 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." + (save-excursion + (goto-char beg) + (let ((string (if delete (delete-and-extract-region beg end) + (buffer-substring beg end)))) + (dolist (filter buffer-substring-filters string) + (setq string (funcall filter 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) --- 2427,2433 ---- 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) --- 2463,2470 ---- 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)