emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch to wdired.el to remove advising code


From: JUAN-LEON Lahoz Garcia
Subject: patch to wdired.el to remove advising code
Date: Wed, 06 Apr 2005 12:20:03 +0200

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 <address@hidden>
-;; Version: 1.91
+;; Author: Juan León Lahoz García <address@hidden>
+;; 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]