;;; viper-ex.el --- functions implementing the Ex commands for Viper
-;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1998, 2000-2012 Free Software Foundation, Inc.
;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
+;; Package: viper
;; This file is part of GNU Emacs.
(defvar ex-addresses nil)
;; This flag is supposed to be set only by `#', `print', and `list',
-;; none of which is implemented. So, it and the pices of the code it
+;; none of which is implemented. So, it and the pieces of the code it
;; controls are dead weight. We keep it just in case this might be
;; needed in the future.
(defvar ex-flag nil)
(defvar viper-keep-reading-filename nil)
(defcustom ex-cycle-other-window t
- "*If t, :n and :b cycles through files and buffers in other window.
+ "If t, :n and :b cycles through files and buffers in other window.
Then :N and :B cycles in the current window. If nil, this behavior is
reversed."
:type 'boolean
:group 'viper-ex)
(defcustom ex-cycle-through-non-files nil
- "*Cycle through *scratch* and other buffers that don't visit any file."
+ "Cycle through *scratch* and other buffers that don't visit any file."
:type 'boolean
:group 'viper-ex)
(format "[^\\\\]\\(\\\\\\\\\\)*\\\\%c" c)))
(setq cont nil)
;; we are at an escaped delimiter: unescape it and continue
- (delete-backward-char 2)
+ (delete-char -2)
(insert c)
(if (eolp)
;; if at eol, exit loop and go to next line
;; Expand \% and \# in ex command
(defun ex-expand-filsyms (cmd buf)
(let (cf pf ret)
- (save-excursion
- (set-buffer buf)
+ (with-current-buffer buf
(setq cf buffer-file-name)
(setq pf (ex-next nil t))) ; this finds alternative file name
(if (and (null cf) (string-match "[^\\]%\\|\\`%" cmd))
(error "No current file to substitute for `%%'"))
(if (and (null pf) (string-match "[^\\]#\\|\\`#" cmd))
(error "No alternate file to substitute for `#'"))
- (save-excursion
- (set-buffer (get-buffer-create viper-ex-tmp-buf-name))
+ (with-current-buffer (get-buffer-create viper-ex-tmp-buf-name)
(erase-buffer)
(insert cmd)
(goto-char (point-min))
ex-cmdfile nil
ex-cmdfile-args "")
(save-excursion
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(skip-chars-forward " \t")
(if (looking-at "!")
(if (and (not (viper-looking-back "[ \t]"))
(switch-to-buffer file))
(if ex-offset
(progn
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(delete-region (point-min) (point-max))
(insert ex-offset "\n")
(goto-char (point-min)))
(if (bobp) (setq cont nil)
(forward-line -1)
(end-of-line)))))
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
;; com-str is the command string, i.e., g/pattern/ or v/pattern'
(setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
(while ex-g-marks
(setq char (string-to-char name))
(error "`%s': Spurious text \"%s\" after mark name"
name (substring name 1)))
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
- (skip-chars-forward " \t")
- (if (looking-at "[a-z]")
- (progn
- (setq char (following-char))
- (forward-char 1)
- (skip-chars-forward " \t")
- (if (not (looking-at "[\n|]"))
- (error "`%s': %s" ex-token viper-SpuriousText)))
- (error "`%s' requires a following letter" ex-token))))
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
+ (skip-chars-forward " \t")
+ (if (looking-at "[a-z]")
+ (progn
+ (setq char (following-char))
+ (forward-char 1)
+ (skip-chars-forward " \t")
+ (if (not (looking-at "[\n|]"))
+ (error "`%s': %s" ex-token viper-SpuriousText)))
+ (error "`%s' requires a following letter" ex-token))))
(save-excursion
(goto-char (car ex-addresses))
(point-to-register (viper-int-to-char (1+ (- char ?a)))))))
(select-window wind)))
(save-window-excursion (select-window wind) (sit-for 1)))
- (save-excursion
- (set-buffer buf)
+ (with-current-buffer buf
(setq viper-related-files-and-buffers-ring old-ring))
(setq viper-local-search-start-marker (point-marker))
;; Ex quit command
(defun ex-quit ()
;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
- (save-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(if (looking-at "!") (forward-char 1)))
(if (< viper-expert-level 3)
(save-buffers-kill-emacs)
;; Optional 3d arg is a string that should replace ' ' to prevent its
;; special meaning
(defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
- (save-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(goto-char (point-min))
(re-search-forward regex-forw nil t)
(let ((beg (point))
;; Ex tag command
(defun ex-tag ()
(let (tag)
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(skip-chars-forward " \t")
(set-mark (point))
(skip-chars-forward "^ |\t\n")
;; Execute shell command
(defun ex-command ()
(let (command)
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(skip-chars-forward " \t")
(setq command (buffer-substring (point) (point-max)))
(end-of-line))
If no args are given, then it runs the last compile command.
Type 'mak ' (including the space) to run make with no args."
(let (args)
- (save-window-excursion
- (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
- (set-buffer viper-ex-work-buf)
+ (with-current-buffer (setq viper-ex-work-buf
+ (get-buffer-create viper-ex-work-buf-name))
(setq args (buffer-substring (point) (point-max)))
(end-of-line))
;; Remove the newline that may (will?) be at the end of the args
-;; arch-tag: 56b80d36-f880-4d10-bd66-85ad91a295db
;;; viper-ex.el ends here