all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Chong Yidong" <cyd@stupidchicken.com>
Cc: emacs-devel@gnu.org
Subject: Re: buffer-substring-filter
Date: Wed, 16 Mar 2005 17:49:24 -0500 (EST)	[thread overview]
Message-ID: <1411.220.255.169.59.1111013364.squirrel@220.255.169.59> (raw)
In-Reply-To: <E1DBbHx-000498-T5@fencepost.gnu.org>

> 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))
  \f
+ (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)

      reply	other threads:[~2005-03-16 22:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-14 12:55 buffer-substring-filter Chong Yidong
2005-03-14 23:44 ` buffer-substring-filter Richard Stallman
2005-03-15  0:29   ` buffer-substring-filter Chong Yidong
2005-03-16 16:22     ` buffer-substring-filter Richard Stallman
2005-03-16 22:49       ` Chong Yidong [this message]

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

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

  git send-email \
    --in-reply-to=1411.220.255.169.59.1111013364.squirrel@220.255.169.59 \
    --to=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.