unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* patch to wdired.el to remove advising code
@ 2005-04-06 10:20 JUAN-LEON Lahoz Garcia
  2005-04-06 11:58 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: JUAN-LEON Lahoz Garcia @ 2005-04-06 10:20 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5263 bytes --]


Hi,

wdired.el advise some functions (query-replace query-replace-regexp
replace-string) for avoiding problems with read-only portions of the
buffer.

But advising functions was not the right thing to do within packages
included in emacs, whenever it can be avoided.

Now, new emacs 22 variable query-replace-skip-read-only can be used
for avoinding this

Patch below removes all the advice-related code of wdired.el and set
this variable to t (after making it buffer local). Maybe any developer
here might want to review and/or apply it.

This patch also updates my email address (the old one was lost years
ago).

[ PS: I wonder if creating a variable `case-commands-skip-read-only'
  would be useful for any other issue other that simplifiying
  wdired. ]

[ PS2: Stefan, thanks for taking the time to including wdired here ]

Regards
juanleon

--- wdired.el.~1.6.~	Fri Feb 18 08:08:18 2005
+++ wdired.el	Wed Apr  6 12:06:01 2005
@@ -3,8 +3,8 @@
 ;; Copyright (C) 2001, 2004  Free Software Foundation, Inc.
 
 ;; Filename: wdired.el
-;; Author: Juan León Lahoz García <juan-leon.lahoz@tecsidel.es>
-;; Version: 1.91
+;; Author: Juan León Lahoz García <juanleon1@gmail.com>
+;; Version: 2.0
 ;; Keywords: dired, environment, files, renaming
 
 ;; This file is part of GNU Emacs.
@@ -157,7 +157,6 @@
 ;;; Code:
 
 (eval-when-compile
-  (require 'advice)
   (defvar dired-backup-overwrite) ; Only in emacs 20.x this is a custom var
   (set (make-local-variable 'byte-compile-dynamic) t))
 
@@ -199,19 +198,6 @@
 		 (other :tag "As in dired mode" t))
   :group 'wdired)
 
-(defcustom wdired-advise-functions t
-  "*If t some editing commands are advised when wdired is loaded.
-The advice only has effect in wdired mode.  These commands are
-`query-replace' `query-replace-regexp' `replace-string', and the
-advice makes them to ignore read-only regions, so no attempts to
-modify these regions are done by them, and so they don't end
-prematurely.
-
-Setting this to nil does not unadvise the functions, if they are
-already advised, but new Emacs will not advise them."
-  :type 'boolean
-  :group 'wdired)
-
 (defcustom wdired-allow-to-redirect-links t
   "*If non-nil, the target of the symbolic links can be changed also.
 In systems without symbolic links support, this variable has no effect
@@ -309,6 +295,7 @@
   (interactive)
   (set (make-local-variable 'wdired-old-content)
        (buffer-substring (point-min) (point-max)))
+  (set (make-local-variable 'query-replace-skip-read-only) t)
   (use-local-map wdired-mode-map)
   (force-mode-line-update)
   (setq buffer-read-only nil)
@@ -662,64 +649,6 @@
 Like original function but it skips read-only words."
   (interactive "p")
   (wdired-xcase-word 'capitalize-word arg))
-
-;; The following code is related to advice some interactive functions
-;; to make some editing commands in wdired mode not to fail trying to
-;; change read-only text. Notice that some advises advice and unadvise
-;; them-self to another functions: search-forward and
-;; re-search-forward. This is to keep these functions advised only
-;; when is necessary. Since they are built-in commands used heavily in
-;; lots of places, to have it permanently advised would cause some
-;; performance loss.
-
-
-(defun wdired-add-skip-in-replace (command)
-  "Advice COMMAND to skip matches while they have read-only properties.
-This is useful to avoid \"read-only\" errors in search and replace
-commands.  This advice only has effect in wdired mode."
-  (eval
-    `(defadvice ,command (around wdired-discard-read-only activate)
-       ,(format "Make %s to work better with wdired,\n%s."  command
-		"skipping read-only matches when invoked without argument")
-       ad-do-it
-       (if (eq major-mode 'wdired-mode)
-	   (while (and ad-return-value
-		       (text-property-any
-			(max 1 (1- (match-beginning 0))) (match-end 0)
-			'read-only t))
-	     ad-do-it))
-       ad-return-value)))
-
-
-(defun wdired-add-replace-advice (command)
-  "Advice COMMAND to skip matches while they have read-only properties.
-This is useful to avoid \"read-only\" errors in search and replace
-commands.  This advice only has effect in wdired mode."
-  (eval
-   `(defadvice ,command (around wdired-grok-read-only activate)
-       ,(format "Make %s to work better with wdired,\n%s."  command
-		"skipping read-only matches when invoked without argument")
-       (if (eq major-mode 'wdired-mode)
-           (progn
-             (wdired-add-skip-in-replace 'search-forward)
-             (wdired-add-skip-in-replace 're-search-forward)
-             (unwind-protect 
-                 ad-do-it
-               (progn
-                 (ad-remove-advice 'search-forward
-                                   'around 'wdired-discard-read-only)
-                 (ad-remove-advice 're-search-forward
-                                   'around 'wdired-discard-read-only)
-                 (ad-update 'search-forward)
-                 (ad-update 're-search-forward))))
-         ad-do-it)
-       ad-return-value)))
-
-
-(if wdired-advise-functions
-    (progn
-      (mapcar 'wdired-add-replace-advice
-              '(query-replace query-replace-regexp replace-string))))
 
 
 ;; The following code deals with changing the access bits (or

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: patch to wdired.el to remove advising code
  2005-04-06 10:20 patch to wdired.el to remove advising code JUAN-LEON Lahoz Garcia
@ 2005-04-06 11:58 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2005-04-06 11:58 UTC (permalink / raw)
  Cc: emacs-devel

> Patch below removes all the advice-related code of wdired.el and set
> this variable to t (after making it buffer local). Maybe any developer
> here might want to review and/or apply it.

Looks good, applied.

> [ PS: I wonder if creating a variable `case-commands-skip-read-only'
>   would be useful for any other issue other that simplifiying
>   wdired. ]

I'm not sure what you mean here.  In any case I probably don't know
the answer.

> [ PS2: Stefan, thanks for taking the time to including wdired here ]

Glad to hear from you again,


        Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-04-06 11:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-06 10:20 patch to wdired.el to remove advising code JUAN-LEON Lahoz Garcia
2005-04-06 11:58 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).