Function: ex-edit

ex-edit is a byte-compiled function defined in viper-ex.el.gz.

Signature

(ex-edit &optional FILE)

Source Code

;; Defined in /usr/src/emacs/lisp/emulation/viper-ex.el.gz
;; Ex edit command
;; In Viper, `e' and `e!' behave identically.  In both cases, the user is
;; asked if current buffer should really be discarded.
;; This command can take multiple file names.  It replaces the current buffer
;; with the first file in its argument list
(defun ex-edit (&optional file)
  (if (not file)
      (viper-get-ex-file))
  (cond ((and (string= ex-file "") buffer-file-name)
	 (setq ex-file  (abbreviate-file-name (buffer-file-name))))
	((string= ex-file "")
	 (error viper-NoFileSpecified)))

     (let (msg do-edit)
       (if buffer-file-name
        (cond ((buffer-modified-p)
               (setq msg
                     (format "Buffer %s is modified.  Discard changes? "
                             (buffer-name))
                     do-edit t))
              ((not (verify-visited-file-modtime (current-buffer)))
               (setq msg
                     (format "File %s changed on disk.  Reread from disk? "
                             buffer-file-name)
                     do-edit t))
              (t (setq do-edit nil))))

       (if do-edit
        (if (yes-or-no-p msg)
            (progn
              (set-buffer-modified-p nil)
              (kill-buffer (current-buffer)))
          (message "Buffer %s was left intact" (buffer-name))))
       ) ; let

  (if (null (setq file (get-file-buffer ex-file)))
      (progn
	;; this also does shell-style globbing
	(ex-find-file
	 ;; replace # and % with the previous/current file
	 (ex-expand-filsyms ex-file (current-buffer)))
	(or (eq major-mode 'dired-mode)
	    (viper-change-state-to-vi))
	(goto-char (point-min)))
    (switch-to-buffer file))
  (if ex-offset
      (progn
	(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)))
	(goto-char (viper-get-ex-address))
	(beginning-of-line)))
  (ex-fixup-history viper-last-ex-prompt ex-file))