branch: externals/idlwave commit ba16611ec5a6cece699b126275f9340e1acdb575 Author: JD Smith <jdtsm...@gmail.com> Commit: JD Smith <jdtsm...@gmail.com>
Use 'with-current-buffer' instead of save-excursion save-excursion does not save anything in a buffer which is switched to in its body. Therefore with-current-buffer is equivalent (or 'save-current-buffer'). From upstream Emacs. --- idlw-help.el | 6 ++--- idlw-shell.el | 86 +++++++++++++++++++++++++---------------------------------- idlwave.el | 36 +++++++++---------------- 3 files changed, 50 insertions(+), 78 deletions(-) diff --git a/idlw-help.el b/idlw-help.el index 7ba430659b..4666900efc 100644 --- a/idlw-help.el +++ b/idlw-help.el @@ -777,8 +777,7 @@ see if a link is set for it. Try extra help functions if necessary." (defun idlwave-help-get-special-help (name type class keyword) "Call the function given by `idlwave-extra-help-function'." (let* ((cw (selected-window)) - (help-pos (save-excursion - (set-buffer (idlwave-help-get-help-buffer)) + (help-pos (with-current-buffer (idlwave-help-get-help-buffer) (let ((buffer-read-only nil)) (funcall idlwave-extra-help-function name type class keyword))))) @@ -1203,8 +1202,7 @@ Useful when source code is displayed as help. See the option (if buf nil (setq buf (get-buffer-create "*IDLWAVE Help*")) - (save-excursion - (set-buffer buf) + (with-current-buffer buf (idlwave-help-mode))) buf)) diff --git a/idlw-shell.el b/idlw-shell.el index 81656977c1..4bab70f1ab 100644 --- a/idlw-shell.el +++ b/idlw-shell.el @@ -1617,8 +1617,7 @@ and then calls `idlwave-shell-send-command' for any pending commands." ;; Gather the command output, and the input as well. (if idlwave-shell-hide-output ;; Hidden output - (save-excursion - (set-buffer idlwave-shell-hidden-output-buffer) + (with-current-buffer idlwave-shell-hidden-output-buffer (setq full-output (buffer-string)) (goto-char (point-max)) (re-search-backward idlwave-shell-prompt-pattern nil t) @@ -1690,8 +1689,7 @@ and then calls `idlwave-shell-send-command' for any pending commands." (let* ((buf (idlwave-shell-buffer)) (win (get-buffer-window buf))) (when (get-buffer buf) - (save-excursion - (set-buffer (idlwave-shell-buffer)) + (with-current-buffer (idlwave-shell-buffer) (goto-char (point-max)) (insert (format "\n\n Process %s %s" process event)) (if (and idlwave-shell-save-command-history @@ -1711,8 +1709,7 @@ and then calls `idlwave-shell-send-command' for any pending commands." (idlwave-shell-cleanup) ;; Run the hook, if possible in the shell buffer. (if (get-buffer buf) - (save-excursion - (set-buffer buf) + (with-current-buffer buf (run-hooks 'idlwave-shell-sentinel-hook)) (run-hooks 'idlwave-shell-sentinel-hook)))) @@ -2178,8 +2175,7 @@ HEAP_GC, /VERBOSE" (defun idlwave-shell-filter-directory () "Get the current directory from `idlwave-shell-command-output'. Change the default directory for the process buffer to concur." - (save-excursion - (set-buffer (idlwave-shell-buffer)) + (with-current-buffer (idlwave-shell-buffer) (idlwave-shell-strip-input) (if (string-match "\\([^\n\r]+\\)[\n\r]" idlwave-shell-command-output) (let ((dir (match-string 1 idlwave-shell-command-output))) @@ -2801,8 +2797,7 @@ Assumes that `idlwave-shell-sources-alist' contains an entry for that module." (message "The source file for module %s is probably not compiled" module) (beep)) - (save-excursion - (set-buffer buf) + (with-current-buffer buf (save-excursion (goto-char (point-min)) (let ((case-fold-search t)) @@ -3138,8 +3133,7 @@ from `idlwave-shell-examine-alist' via mini-buffer shortcut key." (defun idlwave-shell-examine-display () "View the examine command output in a separate buffer." (let (win cur-beg cur-end beg end str) - (save-excursion - (set-buffer (get-buffer-create "*Examine*")) + (with-current-buffer (get-buffer-create "*Examine*") (use-local-map idlwave-shell-examine-map) (setq buffer-read-only nil) (goto-char (point-max)) @@ -3228,13 +3222,11 @@ from `idlwave-shell-examine-alist' via mini-buffer shortcut key." (defun idlwave-shell-examine-display-clear () (interactive) - (save-excursion - (let ((buf (get-buffer "*Examine*"))) - (when (bufferp buf) - (set-buffer buf) - (setq buffer-read-only nil) - (erase-buffer) - (setq buffer-read-only t))))) + (let ((buf (get-buffer "*Examine*"))) + (when (bufferp buf) + (with-current-buffer buf + (let ((inhibit-read-only t)) + (erase-buffer)))))) (defun idlwave-retrieve-expression-from-level (expr level) "Return IDL command to print the expression EXPR from stack level LEVEL. @@ -3329,14 +3321,14 @@ size(___,/DIMENSIONS)" (process (get-buffer-process buffer)) (process-mark (if process (process-mark process))) output-begin output-end) - (save-excursion - (set-buffer buffer) - (goto-char process-mark) - (beginning-of-line) - (setq output-end (point)) - (re-search-backward idlwave-shell-prompt-pattern nil t) - (beginning-of-line 2) - (setq output-begin (point))) + (with-current-buffer buffer + (save-excursion + (goto-char process-mark) + (beginning-of-line) + (setq output-end (point)) + (re-search-backward idlwave-shell-prompt-pattern nil t) + (beginning-of-line 2) + (setq output-begin (point)))) ;; First make sure the shell window is visible (idlwave-display-buffer (idlwave-shell-buffer) @@ -3405,9 +3397,8 @@ If there is a prefix argument, display IDL process." (when (or (not idlwave-shell-is-stopped) (y-or-n-p "Compiling will exit stack, continue? ")) (let ((oldbuf (current-buffer))) - (save-excursion - (set-buffer (idlwave-find-file-noselect - (idlwave-shell-temp-file 'pro) 'tmp)) + (with-current-buffer (idlwave-find-file-noselect + (idlwave-shell-temp-file 'pro) 'tmp) (set (make-local-variable 'comment-start-skip) ";+[ \t]*") (set (make-local-variable 'comment-start) ";") (erase-buffer) @@ -3531,12 +3522,11 @@ of 'count, 'cmd and 'condition. Defaults to 'index." (t (nth 0 (car (cdr bp)))))) (defun idlwave-shell-filter-bp (&optional no-show) - "Get the breakpoints from `idlwave-shell-command-output'. Create -`idlwave-shell-bp-alist' updating breakpoint count and command data -from previous breakpoint list. If NO-SHOW is set, don't update the -breakpoint overlays." - (save-excursion - (set-buffer (get-buffer-create idlwave-shell-bp-buffer)) + "Get the breakpoints from `idlwave-shell-command-output'. +Create `idlwave-shell-bp-alist' updating breakpoint count and command +data from previous breakpoint list. If NO-SHOW is set, don't update +the breakpoint overlays." + (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer) (erase-buffer) (insert idlwave-shell-command-output) (goto-char (point-min)) @@ -4038,8 +4028,7 @@ handled by this command." (idlwave-shell-last-save-and-action-file (if (setq buf (idlwave-get-buffer-visiting idlwave-shell-last-save-and-action-file)) - (save-excursion - (set-buffer buf) + (with-current-buffer buf (save-buffer)))) (t (setq idlwave-shell-last-save-and-action-file (read-file-name "File: "))))) @@ -4116,11 +4105,10 @@ Queries IDL using the string in `idlwave-shell-sources-query'." (defun idlwave-shell-sources-filter () "Get source files from `idlwave-shell-sources-query' output. - (save-excursion - (set-buffer (get-buffer-create idlwave-shell-bp-buffer)) Create `idlwave-shell-sources-alist' consisting of list elements of the form: (module name . (source-file-truename idlwave-internal-filename))" + (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer) (erase-buffer) (insert idlwave-shell-command-output) (goto-char (point-min)) @@ -4192,8 +4180,7 @@ of the form: "Move point to next IDL syntax error." (interactive) (let (frame col) - (save-excursion - (set-buffer idlwave-shell-error-buffer) + (with-current-buffer idlwave-shell-error-buffer (goto-char idlwave-shell-error-last) (if (or (re-search-forward idlwave-shell-syntax-error nil t) @@ -4662,14 +4649,13 @@ idlwave-shell-electric-debug-mode-map) (easy-menu-define idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus" idlwave-shell-menu-def) - (save-excursion - (mapcar (lambda (buf) - (set-buffer buf) - (if (eq major-mode 'idlwave-mode) - (progn - (easy-menu-remove idlwave-mode-debug-menu) - (easy-menu-add idlwave-mode-debug-menu)))) - (buffer-list))))) + (save-current-buffer + (dolist (buf (buffer-list)) + (set-buffer buf) + (if (eq major-mode 'idlwave-mode) + (progn + (easy-menu-remove idlwave-mode-debug-menu) + (easy-menu-add idlwave-mode-debug-menu))))))) ;; The Breakpoint Glyph ------------------------------------------------------- diff --git a/idlwave.el b/idlwave.el index dc2a164f3b..b6b0617ea1 100644 --- a/idlwave.el +++ b/idlwave.el @@ -5556,8 +5556,7 @@ directories and save the routine info. idlwave-path-alist path-alist ; for library-path instead idlwave-true-path-alist nil) (if idlwave-auto-write-paths (idlwave-write-paths)) - (save-excursion - (set-buffer (get-buffer-create "*idlwave-scan.pro*")) + (with-current-buffer (get-buffer-create "*idlwave-scan.pro*") (idlwave-mode) (setq dirs-alist (reverse path-alist)) (while (setq dir (pop dirs-alist)) @@ -5862,9 +5861,8 @@ end (defun idlwave-shell-compile-helper-routines (&optional wait) (unless (and idlwave-idlwave_routine_info-compiled (file-readable-p (idlwave-shell-temp-file 'rinfo))) - (save-excursion - (set-buffer (idlwave-find-file-noselect - (idlwave-shell-temp-file 'pro))) + (with-current-buffer (idlwave-find-file-noselect + (idlwave-shell-temp-file 'pro)) (erase-buffer) (insert idlwave-routine-info.pro) (save-buffer 0)) @@ -7215,14 +7213,12 @@ If these don't exist, a letter in the string is automatically selected." (defun idlwave-set-local (var value &optional buffer) "Set the buffer-local value of VAR in BUFFER to VALUE." - (save-excursion - (set-buffer (or buffer (current-buffer))) + (with-current-buffer (or buffer (current-buffer)) (set (make-local-variable var) value))) (defun idlwave-local-value (var &optional buffer) "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER." - (save-excursion - (set-buffer (or buffer (current-buffer))) + (with-current-buffer (or buffer (current-buffer)) (and (local-variable-p var (current-buffer)) (symbol-value var)))) @@ -7238,8 +7234,7 @@ If these don't exist, a letter in the string is automatically selected." (apply 'display-completion-list list ':activate-callback 'idlwave-default-choose-completion cl-args)) - (save-excursion - (set-buffer "*Completions*") + (with-current-buffer "*Completions*" (use-local-map (or idlwave-completion-map (setq idlwave-completion-map @@ -7266,8 +7261,7 @@ If these don't exist, a letter in the string is automatically selected." "Display completion list and install the choose wrappers." (with-output-to-temp-buffer "*Completions*" (display-completion-list list)) - (save-excursion - (set-buffer "*Completions*") + (with-current-buffer "*Completions*" (use-local-map (or idlwave-completion-map (setq idlwave-completion-map @@ -7882,8 +7876,7 @@ associated TAG, if any." (defun idlwave-completion-fontify-classes () "Goto the *Completions* buffer and fontify the class info." (when (featurep 'font-lock) - (save-excursion - (set-buffer "*Completions*") + (with-current-buffer "*Completions*" (save-excursion (goto-char (point-min)) (let ((buffer-read-only nil)) @@ -8430,9 +8423,8 @@ If we do not know about MODULE, just return KEYWORD literally." ((null calling-seq) (error "Calling sequence of %s %s not available" type name)) (t - (save-excursion - (move-marker idlwave-rinfo-marker (point)) - (set-buffer (get-buffer-create "*Help*")) + (move-marker idlwave-rinfo-marker (point)) + (with-current-buffer (get-buffer-create "*Help*") (use-local-map idlwave-rinfo-map) (setq buffer-read-only nil) (erase-buffer) @@ -8800,8 +8792,7 @@ can be used to detect possible name clashes during this process." (apply 'idlwave-do-find-module (get-text-property (point) 'find-args)))) (message "Compiling list...( 0%%)") - (save-excursion - (set-buffer (get-buffer-create "*Shadows*")) + (with-current-buffer (get-buffer-create "*Shadows*") (setq buffer-read-only nil) (erase-buffer) (while (setq routine (pop routines)) @@ -9410,8 +9401,7 @@ This function was written since `list-abbrevs' looks terrible for IDLWAVE mode." (princ (format fmt str rpl func))) abbrevs))) ;; Make sure each abbreviation uses only one display line - (save-excursion - (set-buffer "*Help*") + (with-current-buffer "*Help*" (setq truncate-lines t))) ;; Add .pro files to speedbar for support, if it's loaded @@ -9421,8 +9411,6 @@ This function was written since `list-abbrevs' looks terrible for IDLWAVE mode." ;; Will only work on systems which support this. (or idlwave-routines (idlwave-start-load-rinfo-timer)) -;;;###autoload (add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode)) - ;; Run the hook (run-hooks 'idlwave-load-hook) (provide 'idlwave)