changeset 96276:5f58c2a66de7

* buff-menu.el: Use with-current-buffer and inhibit-read-only. (Buffer-menu-toggle-read-only): Avoid vc-toggle-read-only. * bs.el: Use with-current-buffer. Simplify. (bs-toggle-readonly): Avoid vc-toggle-read-only.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 25 Jun 2008 15:13:03 +0000
parents 1730aeea7acf
children f70dcd8d61da
files lisp/ChangeLog lisp/bs.el lisp/buff-menu.el
diffstat 3 files changed, 42 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Jun 25 15:10:16 2008 +0000
+++ b/lisp/ChangeLog	Wed Jun 25 15:13:03 2008 +0000
@@ -1,5 +1,11 @@
 2008-06-25  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* buff-menu.el: Use with-current-buffer and inhibit-read-only.
+	(Buffer-menu-toggle-read-only): Avoid vc-toggle-read-only.
+
+	* bs.el: Use with-current-buffer.  Simplify.
+	(bs-toggle-readonly): Avoid vc-toggle-read-only.
+
 	* eshell/esh-cmd.el (eshell-manipulate): Check eshell-debug-command
 	is bound before using it.
 
--- a/lisp/bs.el	Wed Jun 25 15:10:16 2008 +0000
+++ b/lisp/bs.el	Wed Jun 25 15:13:03 2008 +0000
@@ -129,6 +129,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
+
 ;; ----------------------------------------------------------------------
 ;; Globals for customization
 ;; ----------------------------------------------------------------------
@@ -373,9 +375,7 @@
 
 (defun bs--sort-by-size (b1 b2)
   "Compare buffers B1 and B2 by buffer size."
-  (save-excursion
-    (< (progn (set-buffer b1) (buffer-size))
-       (progn (set-buffer b2) (buffer-size)))))
+  (< (buffer-size b1) (buffer-size b2)))
 
 (defcustom bs-sort-functions
   '(("by name"     bs--sort-by-name     "Buffer" region)
@@ -814,11 +814,9 @@
 (defun bs-save ()
   "Save buffer on current line."
   (interactive)
-  (let ((buffer (bs--current-buffer)))
-    (save-excursion
-      (set-buffer buffer)
-      (save-buffer))
-    (bs--update-current-line)))
+  (with-current-buffer (bs--current-buffer)
+    (save-buffer)
+    (bs--update-current-line))
 
 (defun bs-visit-tags-table ()
   "Visit the tags table in the buffer on this line.
@@ -832,16 +830,12 @@
 (defun bs-toggle-current-to-show ()
   "Toggle status of showing flag for buffer in current line."
   (interactive)
-  (let ((buffer (bs--current-buffer))
-	res)
-    (save-excursion
-      (set-buffer buffer)
-      (setq res (cond ((null bs-buffer-show-mark)
-		       'never)
-		      ((eq bs-buffer-show-mark 'never)
-		       'always)
-		      (t nil)))
-      (setq bs-buffer-show-mark res))
+  (let ((res
+         (with-current-buffer (bs--current-buffer)
+           (setq bs-buffer-show-mark (case bs-buffer-show-mark
+                                       ((nil)   'never)
+                                       ((never) 'always)
+                                       (t       nil))))))
     (bs--update-current-line)
     (bs--set-window-height)
     (bs--show-config-message res)))
@@ -969,21 +963,17 @@
 
 (defun bs-toggle-readonly ()
   "Toggle read-only status for buffer on current line.
-Uses function `vc-toggle-read-only'."
+Uses function `toggle-read-only'."
   (interactive)
-  (let ((buffer (bs--current-buffer)))
-    (save-excursion
-      (set-buffer buffer)
-      (vc-toggle-read-only))
-    (bs--update-current-line)))
+  (with-current-buffer (bs--current-buffer)
+    (toggle-read-only))
+  (bs--update-current-line))
 
 (defun bs-clear-modified ()
   "Set modified flag for buffer on current line to nil."
   (interactive)
-  (let ((buffer (bs--current-buffer)))
-    (save-excursion
-      (set-buffer buffer)
-      (set-buffer-modified-p nil)))
+  (with-current-buffer (bs--current-buffer)
+    (set-buffer-modified-p nil))
   (bs--update-current-line))
 
 (defun bs--nth-wrapper (count fun &rest args)
@@ -1352,8 +1342,7 @@
   (let ((string "")
 	(to-much 0)
         (apply-args (append (list bs--buffer-coming-from bs-current-list))))
-    (save-excursion
-      (set-buffer buffer)
+    (with-current-buffer buffer
       (dolist (column bs-attributes-list)
 	(let* ((min (bs--get-value (nth 1 column)))
 	       (new-string (bs--format-aux (bs--get-value (nth 4 column) ; fun
--- a/lisp/buff-menu.el	Wed Jun 25 15:10:16 2008 +0000
+++ b/lisp/buff-menu.el	Wed Jun 25 15:13:03 2008 +0000
@@ -305,7 +305,7 @@
   "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
   (interactive)
   (when (Buffer-menu-no-header)
-    (let ((buffer-read-only nil))
+    (let ((inhibit-read-only t))
       (delete-char 1)
       (insert ?>)
       (forward-line 1))))
@@ -317,8 +317,8 @@
   (when (Buffer-menu-no-header)
     (let* ((buf (Buffer-menu-buffer t))
 	   (mod (buffer-modified-p buf))
-	   (readonly (save-excursion (set-buffer buf) buffer-read-only))
-	   (buffer-read-only nil))
+	   (readonly (with-current-buffer buf buffer-read-only))
+	   (inhibit-read-only t))
       (delete-char 3)
       (insert (if readonly (if mod " %*" " % ") (if mod "  *" "   ")))))
   (forward-line (if backup -1 1)))
@@ -336,7 +336,7 @@
 Negative arg means delete backwards."
   (interactive "p")
   (when (Buffer-menu-no-header)
-    (let ((buffer-read-only nil))
+    (let ((inhibit-read-only t))
       (if (or (null arg) (= arg 0))
 	  (setq arg 1))
       (while (> arg 0)
@@ -361,7 +361,7 @@
   "Mark buffer on this line to be saved by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command."
   (interactive)
   (when (Buffer-menu-no-header)
-    (let ((buffer-read-only nil))
+    (let ((inhibit-read-only t))
       (forward-char 2)
       (delete-char 1)
       (insert ?S)
@@ -370,14 +370,13 @@
 (defun Buffer-menu-not-modified (&optional arg)
   "Mark buffer on this line as unmodified (no changes to save)."
   (interactive "P")
-  (save-excursion
-    (set-buffer (Buffer-menu-buffer t))
+  (with-current-buffer (Buffer-menu-buffer t)
     (set-buffer-modified-p arg))
   (save-excursion
    (beginning-of-line)
    (forward-char 2)
    (if (= (char-after) (if arg ?\s ?*))
-       (let ((buffer-read-only nil))
+       (let ((inhibit-read-only t))
 	 (delete-char 1)
 	 (insert (if arg ?* ?\s))))))
 
@@ -393,17 +392,16 @@
     (Buffer-menu-beginning)
     (while (re-search-forward "^..S" nil t)
       (let ((modp nil))
-	(save-excursion
-	  (set-buffer (Buffer-menu-buffer t))
+	(with-current-buffer (Buffer-menu-buffer t)
 	  (save-buffer)
 	  (setq modp (buffer-modified-p)))
-	(let ((buffer-read-only nil))
+	(let ((inhibit-read-only t))
 	  (delete-char -1)
 	  (insert (if modp ?* ?\s))))))
   (save-excursion
     (Buffer-menu-beginning)
     (let ((buff-menu-buffer (current-buffer))
-	  (buffer-read-only nil))
+	  (inhibit-read-only t))
       (while (re-search-forward "^D" nil t)
 	(forward-char -1)
 	(let ((buf (Buffer-menu-buffer nil)))
@@ -430,7 +428,7 @@
     (Buffer-menu-beginning)
     (while (re-search-forward "^>" nil t)
       (setq tem (Buffer-menu-buffer t))
-      (let ((buffer-read-only nil))
+      (let ((inhibit-read-only t))
 	(delete-char -1)
 	(insert ?\s))
       (or (eq tem buff) (memq tem others) (setq others (cons tem others))))
@@ -478,8 +476,7 @@
   "Select the buffer whose line you click on."
   (interactive "e")
   (let (buffer)
-    (save-excursion
-      (set-buffer (window-buffer (posn-window (event-end event))))
+    (with-current-buffer (window-buffer (posn-window (event-end event)))
       (save-excursion
 	(goto-char (posn-point (event-end event)))
 	(setq buffer (Buffer-menu-buffer t))))
@@ -525,15 +522,14 @@
   "Toggle read-only status of buffer on this line, perhaps via version control."
   (interactive)
   (let (char)
-    (save-excursion
-      (set-buffer (Buffer-menu-buffer t))
-      (vc-toggle-read-only)
+    (with-current-buffer (Buffer-menu-buffer t)
+      (toggle-read-only)
       (setq char (if buffer-read-only ?% ?\s)))
     (save-excursion
       (beginning-of-line)
       (forward-char 1)
       (if (/= (following-char) char)
-          (let (buffer-read-only)
+          (let ((inhibit-read-only t))
             (delete-char 1)
             (insert char))))))
 
@@ -545,7 +541,7 @@
       (beginning-of-line)
       (bury-buffer (Buffer-menu-buffer t))
       (let ((line (buffer-substring (point) (progn (forward-line 1) (point))))
-            (buffer-read-only nil))
+            (inhibit-read-only t))
         (delete-region (point) (progn (forward-line -1) (point)))
         (goto-char (point-max))
         (insert line))
@@ -612,7 +608,7 @@
     (if (< column 2) (setq column 2))
     (if (> column 5) (setq column 5)))
   (setq Buffer-menu-sort-column column)
-  (let (buffer-read-only l buf m1 m2)
+  (let ((inhibit-read-only t) l buf m1 m2)
     (save-excursion
       (Buffer-menu-beginning)
       (while (not (eobp))
@@ -625,7 +621,6 @@
 	      (push (list buf m1 m2) l)))
 	(forward-line)))
     (Buffer-menu-revert)
-    (setq buffer-read-only)
     (save-excursion
       (Buffer-menu-beginning)
       (while (not (eobp))