Skip to content

Commit

Permalink
replaced most of the
Browse files Browse the repository at this point in the history
(save-excursion
  (set-buffer xxx)
  ...)

with

(with-current-buffer xxx
  ...)

This is a) much saver and b) prevents Emacs 23.2 from nagging a lot of warnings.
  • Loading branch information
berndl committed Feb 23, 2010
1 parent fd404cb commit 5665d49
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 119 deletions.
6 changes: 2 additions & 4 deletions ecb-analyse.el
Expand Up @@ -392,8 +392,7 @@ should be displayed with. LIST is a list of tags for this bucket. NODETYPE is
an integer which will be added as type to the nodes created for the elements
of LIST."
(when list
(save-excursion
(set-buffer ecb-analyse-buffer-name)
(with-current-buffer ecb-analyse-buffer-name
(let* ((bucket-name-formatted
(ecb-merge-face-into-text (ecb-format-bucket-name bucket-name)
ecb-analyse-bucket-node-face))
Expand Down Expand Up @@ -532,8 +531,7 @@ ECB-analyse-window is not visible in current layout."
(defun ecb-analyse-show-tag-info-in-temp-buffer (info-string)
"Display INFO-STRING in a temp-buffer in the edit-area."
(with-output-to-temp-buffer "*Tag Information*"
(save-excursion
(set-buffer "*Tag Information*")
(with-current-buffer "*Tag Information*"
(insert info-string)))
;; Make it small
(shrink-window-if-larger-than-buffer
Expand Down
3 changes: 1 addition & 2 deletions ecb-autogen.el
Expand Up @@ -146,8 +146,7 @@ does nothing."
;; XEmacs adds autom. the provide statement but for GNU Emacs we must do
;; this:
(when (not ecb-running-xemacs)
(save-excursion
(set-buffer (find-file-noselect (expand-file-name ecb-autogen-file)))
(with-current-buffer (find-file-noselect (expand-file-name ecb-autogen-file))
(goto-char (point-min))
(when (not (re-search-forward (format "^(provide '%s)"
ecb-autoload-feature) nil t))
Expand Down
3 changes: 1 addition & 2 deletions ecb-common-browser.el
Expand Up @@ -2158,8 +2158,7 @@ the returned string: 'tree-buffer-image-start which holds 0 as value and
value."
(let ((image nil)
(ret nil))
(save-excursion
(set-buffer name-of-buffer)
(with-current-buffer name-of-buffer
(setq image (and icon-name (tree-buffer-find-image icon-name)))
(setq ret
(if image
Expand Down
3 changes: 1 addition & 2 deletions ecb-compilation.el
Expand Up @@ -220,8 +220,7 @@ either
(if (ecb-compilation-registered-buffer-p (buffer-name buffer))
buffer
;;else test if this is a valid buffer by mode
(if (save-excursion
(set-buffer buffer)
(if (with-current-buffer buffer
(member major-mode (ecb-compilation-major-modes)))
buffer
;;else test if this is a regular compilation buffer
Expand Down
9 changes: 3 additions & 6 deletions ecb-eshell.el
Expand Up @@ -272,17 +272,15 @@ ECB and if either this function is called interactively or
ecb-eshell-buffer-list)))
(my-reference-directory default-directory)
(my-eshell-directory (and (bufferp my-eshell-buffer)
(save-excursion
(set-buffer my-eshell-buffer)
(with-current-buffer my-eshell-buffer
default-directory))))
(when (and (bufferp my-eshell-buffer)
(stringp my-reference-directory)
(stringp my-eshell-directory)
(not (ecb-string= (ecb-fix-filename my-reference-directory)
(ecb-fix-filename my-eshell-directory))))
(ecb-eshell-save-buffer-history
(save-excursion
(set-buffer my-eshell-buffer)
(with-current-buffer my-eshell-buffer
;; make sure we have a clean eshell-command-line
(goto-char (point-max))
(eshell-bol)
Expand Down Expand Up @@ -359,8 +357,7 @@ enlarge the compile-window over half of the frame-height and also not below
(ecb-normalize-number ecb-compile-window-height
(1- (frame-height))))
(ecb-enlarged-compilation-window-max-height
(max (min (save-excursion
(set-buffer (window-buffer ecb-compile-window))
(max (min (with-current-buffer (window-buffer ecb-compile-window)
;; we want to see the old command line too and 2
;; must be added because we have a modeline and one
;; empty line cause of the (recenter -2) in
Expand Down
43 changes: 27 additions & 16 deletions ecb-file-browser.el
Expand Up @@ -2377,8 +2377,7 @@ added.")
(y-or-n-p "Remove history entry for this buffer?")))
;; we must do this even when the history is not visible!!
;; the history should be always up-to-date
(save-excursion
(set-buffer ecb-history-buffer-name)
(with-current-buffer ecb-history-buffer-name
(tree-buffer-remove-node node))
;; if we have removed a node then we must ignore the related buffer
;; when rebuilding the history - otherwise the node would be added
Expand Down Expand Up @@ -2408,8 +2407,7 @@ bucket)."
(defun ecb-history-content-all-dead-buffers-alist ()
"Return alist with items \(<buffer-name> . <file-name>) for dead buffers
entries of the history-buffer."
(save-excursion
(set-buffer ecb-history-buffer-name)
(with-current-buffer ecb-history-buffer-name
(delq nil (tree-node-map-subtree
(tree-buffer-get-root)
(function
Expand Down Expand Up @@ -2532,8 +2530,7 @@ Returns t if the current history filter has been applied otherwise nil."
(if ecb-running-xemacs 0)))
(mode (symbol-name
(if (ecb-buffer-obj (car elem))
(save-excursion
(set-buffer (ecb-buffer-obj (car elem)))
(with-current-buffer (ecb-buffer-obj (car elem))
major-mode)
;; for dead buffers of the
;; history we use auto-mode-alist
Expand Down Expand Up @@ -2562,8 +2559,7 @@ Returns t if the current history filter has been applied otherwise nil."
;; toplevel bucket of the history-buffer. This is the state before
;; rebuilding the history!
(curr-bucket-expand-status-alist
(save-excursion
(set-buffer ecb-history-buffer-name)
(with-current-buffer ecb-history-buffer-name
(delq nil (mapcar (function
(lambda (node)
(when (= (tree-node->type node)
Expand All @@ -2579,8 +2575,7 @@ Returns t if the current history filter has been applied otherwise nil."
;; additonal-dead-history-buffer-alist
;; indirect-buffer-base
;; aggregated-indirect-buffers-alist)
(save-excursion
(set-buffer ecb-history-buffer-name)
(with-current-buffer ecb-history-buffer-name
(tree-buffer-clear-tree)
(dolist (bucket-elem aggregated-alist-with-buckets)
(let* ((best-matching-sp (if (eq ecb-history-make-buckets 'directory-with-source-path)
Expand Down Expand Up @@ -2726,8 +2721,7 @@ Returns t if the current history filter has been applied otherwise nil."
(tree-buffer-update)
(tree-buffer-highlight-node-by-data/name (ecb-path-selected-source)))
(prog1
(if (and (save-excursion
(set-buffer ecb-history-buffer-name)
(if (and (with-current-buffer ecb-history-buffer-name
(tree-buffer-empty-p))
(not (ecb-history-filter-reset-p)))
(progn
Expand Down Expand Up @@ -2769,8 +2763,7 @@ indirect-buffer."
;; display the methods in the METHOD-buffer. We can not go back to
;; the edit-window because then the METHODS buffer would be
;; immediately updated with the methods of the edit-window.
(save-excursion
(set-buffer (ecb-source-get-buffer source))
(with-current-buffer (ecb-source-get-buffer source)
(ecb-path-selected-source-set (ecb-source-get-filename source)
(buffer-name))
(ecb-update-methods-buffer--internal 'scroll-to-begin nil t t))
Expand Down Expand Up @@ -3352,6 +3345,25 @@ the SOURCES-cache."
(require 'vc-bzr)
'BZR))

;; Mercurial support
;; TODO: Klaus Berndl <klaus.berndl@sdm.de>: if this works we should add it to
;; `ecb-vc-supported-backends'.

(defun ecb-vc-dir-managed-by-HG (directory)
"Return 'GIT if DIRECTORY is managed by Mercurial. nil if not.
Because with Mercurial only the top-most directory of a source-tree has a subdir
.hg this function tries recursively upwards if there is a .hg-subdir."
;; With XEmacs we must first load the vc-hooks which contain the function
;; `vc-find-root'
(when ecb-running-xemacs
(ignore-errors (vc-load-vc-hooks)))
(and (locate-library "vc-hg")
(fboundp 'vc-find-root)
(vc-find-root directory ".hg")
(require 'vc)
(require 'vc-hg)
'HG))

;; Git support

(defun ecb-vc-dir-managed-by-GIT (directory)
Expand Down Expand Up @@ -4482,8 +4494,7 @@ edit-windows. Otherwise return nil."
;; current buffer is always the history-buffer - we have to set
;; the buffer representing data (buf) as current buffer - otherwise
;; ecb-kill-buffer-hook would not run correctly
(save-excursion
(set-buffer buf)
(with-current-buffer buf
(kill-buffer buf)
(ecb-add-buffers-to-history-new)))))

Expand Down
6 changes: 2 additions & 4 deletions ecb-layout.el
Expand Up @@ -777,8 +777,7 @@ then set always nil!"
(unless ecb-running-xemacs
(let ((l (ecb-canonical-ecb-windows-list)))
(dolist (w l)
(save-excursion
(set-buffer (window-buffer w))
(with-current-buffer (window-buffer w)
(setq window-size-fixed (if (and (not ecb-running-gnu-emacs-version-22)
ecb-compile-window-height)
nil
Expand Down Expand Up @@ -6138,8 +6137,7 @@ Emacs)."
(if (and (ecb-compile-window-live-p)
(member ecb-compile-window-temporally-enlarge
'(after-display both))
(or (save-excursion
(set-buffer (window-buffer ecb-compile-window))
(or (with-current-buffer (window-buffer ecb-compile-window)
(equal major-mode 'compilation-mode))
(if ecb-running-xemacs
temp-buffer-shrink-to-fit
Expand Down
57 changes: 19 additions & 38 deletions ecb-method-browser.el
Expand Up @@ -2066,8 +2066,7 @@ onto the whole tag-table are performed by `ecb-apply-tag-table-filters'.")
&optional tag-class)
"Filter the Methods-buffer by a tag-class."
(let* ((curr-semantic-symbol->name-assoc-list
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(ecb--semantic-symbol->name-assoc-list)))
(choice (or tag-class
(ecb-query-string "Tag-class filter:"
Expand Down Expand Up @@ -2253,13 +2252,11 @@ used; if point does not stay on a tag then nil is returned."
"Display only the current-type and its contents in the methods-buffer. The
argument INVERSE is ignored here."
(let* ((curr-type-tag (or (and (ecb--semantic-tag-p tag)
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(ecb-get-type-tag-of-tag tag)))
(cond ((ecb-point-in-edit-window-number)
(if (ecb--semantic-active-p)
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(ecb-get-type-tag-of-tag (ecb-get-real-curr-tag)))))
((equal (current-buffer)
(ecb-buffer-obj ecb-methods-buffer-name))
Expand All @@ -2268,8 +2265,7 @@ argument INVERSE is ignored here."
(tree-node->data (ecb-get-type-node-of-node node)))))
(t (ecb-error "ECB can not identify the current-type-tag!")))))
(curr-tag-type-name-hierachy (and curr-type-tag
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(ecb-get-type-name-hierarchy-of-current-tag
curr-type-tag)))))
(if (and curr-type-tag curr-tag-type-name-hierachy)
Expand Down Expand Up @@ -2420,13 +2416,11 @@ applied default-tag-filters."
(defun ecb-methods-filter-internal (inverse &optional filter-type)
"FILTER-TYPE has to be one of the symbols 'regexp, 'protection,
'tag-class, 'curr-type, 'function, 'no-filter or 'delete-last."
(if (save-excursion
(set-buffer ecb-methods-buffer-name)
(if (with-current-buffer ecb-methods-buffer-name
(tree-buffer-empty-p))
(message "There is nothing to filter in an empty Methods-buffer!")
(let* ((source-buffer (ecb-get-source-buffer-for-tag-filter))
(semantic-source-p (save-excursion
(set-buffer source-buffer)
(semantic-source-p (with-current-buffer source-buffer
(ecb--semantic-active-p)))
(choice (or filter-type
(intern (ecb-query-string
Expand Down Expand Up @@ -2466,8 +2460,7 @@ should be displayed in the modeline of the methods-buffer. If REMOVE-LAST is
not nil then the topmost filter will be removed and all other arguments unless
SOURCE-BUFFER arguments are ignored. Returns t if the filter has been applied
otherwise nil."
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(if (and (not remove-last)
(member filtertype '(protection tag-class curr-type))
(not (ecb--semantic-active-p)))
Expand Down Expand Up @@ -2503,8 +2496,7 @@ otherwise nil."
(setq ecb-methods-user-filter-alist
(cons (cons source-buffer filters) ecb-methods-user-filter-alist)))))
(when (buffer-live-p source-buffer)
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(if (ecb--semantic-active-p)
;; For semantic-sources we do not use `ecb-rebuild-methods-buffer)'
;; because this would always reparse the source-buffer even if not
Expand All @@ -2514,8 +2506,7 @@ otherwise nil."
(ecb-rebuild-methods-buffer-with-tagcache
(ecb-fetch-semantic-tags)))
(ecb-rebuild-methods-buffer-fully)))
(if (save-excursion
(set-buffer ecb-methods-buffer-name)
(if (with-current-buffer ecb-methods-buffer-name
(tree-buffer-empty-p))
(progn
(ecb-methods-filter-apply nil nil nil "" "" source-buffer t)
Expand Down Expand Up @@ -2872,8 +2863,7 @@ partial reparse and update-mechanism."
(let* ((id (ecb-overlay-get (ecb--semantic-tag-overlay tag-for-update)
'ECB-tree-node-id))
(node (when id
(save-excursion
(set-buffer ecb-methods-buffer-name)
(with-current-buffer ecb-methods-buffer-name
(tree-node-search-subtree-by-id (tree-buffer-get-root)
id))))
(data-parent (and node
Expand All @@ -2892,8 +2882,7 @@ partial reparse and update-mechanism."
(ecb-partial-reparse-debug "We update node for tag:%s with new name:%s"
(ecb--semantic-tag-name tag-for-update)
new-tag-name)
(save-excursion
(set-buffer ecb-methods-buffer-name)
(with-current-buffer ecb-methods-buffer-name
(tree-buffer-update-node node
new-tag-name
'use-old-value
Expand Down Expand Up @@ -2943,8 +2932,7 @@ partial reparse and update-mechanism."
"Return not nil if FILENAME is already displayed in a buffer and if semantic
is active for this buffer."
(and (get-file-buffer filename)
(save-excursion
(set-buffer (get-file-buffer filename))
(with-current-buffer (get-file-buffer filename)
(ecb--semantic-active-p))))


Expand Down Expand Up @@ -3127,8 +3115,7 @@ TABLE."

(defun ecb-methods-get-data-store (key)
"Get the value for KEY from the tree-buffer-data-store of the Methods-buffer."
(save-excursion
(set-buffer ecb-methods-buffer-name)
(with-current-buffer ecb-methods-buffer-name
(cdr (assoc key (tree-buffer-get-data-store)))))


Expand Down Expand Up @@ -3314,8 +3301,7 @@ to be rescanned/reparsed and therefore the Method-buffer will be rebuild too."
;; cache can not work because the buffer-string is a "copy" of the
;; tree-buffer and therefore the cached buffer-string can not be updated
;; automatically.
(save-excursion
(set-buffer ecb-methods-buffer-name)
(with-current-buffer ecb-methods-buffer-name
;; we store in the tree-buffer the buffer and the major-mode for which
;; the tree-buffer has been build. In no other place the data-store
;; will be set!
Expand Down Expand Up @@ -3786,8 +3772,7 @@ file types which are parsed by imenu or etags \(see
;; expanded to max level...
(when ecb-expand-methods-switch-off-auto-expand
(ecb-toggle-auto-expand-tag-tree -1))
(ecb-expand-methods-node-internal (save-excursion
(set-buffer ecb-methods-buffer-name)
(ecb-expand-methods-node-internal (with-current-buffer ecb-methods-buffer-name
(tree-buffer-get-root))
level force-all t t)))

Expand Down Expand Up @@ -3935,8 +3920,7 @@ This function is fully fitting the needs of the option
;; included file
(unless destination
(when (equal 'include (ecb--semantic-tag-class node-tag))
(save-excursion
(set-buffer (ecb-path-selected-source 'buffer))
(with-current-buffer (ecb-path-selected-source 'buffer)
(let ((file (ecb--semantic-dependency-tag-file node-tag)))
(when (and file (ecb-file-exists-p file))
(setq destination (list (ecb-source-make file)
Expand Down Expand Up @@ -4303,8 +4287,7 @@ Returns current point."
(defun ecb-methods-menu-activate-hs ()
"Activates `hs-minor-mode' in the buffer of `ecb-path-selected-source'. If
this fails then nil is returned otherwise t."
(save-excursion
(set-buffer (get-file-buffer (ecb-path-selected-source 'file)))
(with-current-buffer (get-file-buffer (ecb-path-selected-source 'file))
(if (or (not (boundp 'hs-minor-mode))
(not hs-minor-mode))
(if (fboundp 'hs-minor-mode)
Expand Down Expand Up @@ -4464,8 +4447,7 @@ edit-windows. Otherwise return nil."
;; we must not use here (ecb-methods-get-data-store
;; 'semantic-symbol->name-assoc-list) because we do not want the
;; function-prototypes...
(save-excursion
(set-buffer (ecb-methods-get-data-store 'source-buffer))
(with-current-buffer (ecb-methods-get-data-store 'source-buffer)
(ecb--semantic-symbol->name-assoc-list)))
(prot-list '("private" "protected" "public"))
(prot-menu-elems nil)
Expand Down Expand Up @@ -4732,8 +4714,7 @@ moved over it."
;; we ca not use format here because XEmacs-format removes all
;; text-properties!
(insert (concat (make-string indent ? )
(save-excursion
(set-buffer source-buffer)
(with-current-buffer source-buffer
(ecb--semantic-format-tag-uml-prototype tag parent t))
", tag-class: "
(format "%s" (ecb--semantic-tag-class tag))
Expand Down

0 comments on commit 5665d49

Please sign in to comment.