/[emacs]/emacs/lisp/emulation/viper-ex.el
ViewVC logotype

Diff of /emacs/lisp/emulation/viper-ex.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.44 by kifer, Tue Apr 16 05:49:11 2002 UTC revision 1.44.2.1 by miles, Fri Apr 4 06:20:19 2003 UTC
# Line 150  Line 150 
150          ("set"                  (ex-set))          ("set"                  (ex-set))
151          ("shell"                (ex-shell))          ("shell"                (ex-shell))
152          ("source"               (ex-source))          ("source"               (ex-source))
153          ("stop"                 (suspend-emacs))          ("stop"                 (suspend-emacs))
154          ("sr"                   (ex-substitute t t))          ("sr"                   (ex-substitute t t))
155          ("submitReport"         (viper-submit-report))          ("submitReport"         (viper-submit-report))
156          ("substitute"           (ex-substitute) is-mashed)          ("substitute"           (ex-substitute) is-mashed)
# Line 165  Line 165 
165          ("v"                    "vglobal")          ("v"                    "vglobal")
166          ("version"              (viper-version))          ("version"              (viper-version))
167          ("vglobal"              (ex-global t) is-mashed)          ("vglobal"              (ex-global t) is-mashed)
168          ("visual"               (ex-edit))          ("visual"               (ex-edit))
169          ("w"                    "write")          ("w"                    "write")
170          ("wq"                   (ex-write t))          ("wq"                   (ex-write t))
171          ("write"                (ex-write nil))          ("write"                (ex-write nil))
# Line 238  Line 238 
238    
239    
240  ;; A-list of Ex variables that can be set using the :set command.  ;; A-list of Ex variables that can be set using the :set command.
241  (defconst ex-variable-alist  (defconst ex-variable-alist
242    '(("wrapscan") ("ws") ("wrapmargin") ("wm")    '(("wrapscan") ("ws") ("wrapmargin") ("wm")
243      ("tabstop-global") ("ts-g") ("tabstop") ("ts")      ("tabstop-global") ("ts-g") ("tabstop") ("ts")
244      ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")      ("showmatch") ("sm") ("shiftwidth") ("sw") ("shell") ("sh")
245      ("readonly") ("ro")      ("readonly") ("ro")
246      ("nowrapscan") ("nows") ("noshowmatch") ("nosm")      ("nowrapscan") ("nows") ("noshowmatch") ("nosm")
247      ("noreadonly") ("noro") ("nomagic") ("noma")      ("noreadonly") ("noro") ("nomagic") ("noma")
248      ("noignorecase") ("noic")      ("noignorecase") ("noic")
249      ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")      ("noautoindent-global") ("noai-g") ("noautoindent") ("noai")
250      ("magic") ("ma") ("ignorecase") ("ic")      ("magic") ("ma") ("ignorecase") ("ic")
251      ("autoindent-global") ("ai-g") ("autoindent") ("ai")      ("autoindent-global") ("ai-g") ("autoindent") ("ai")
252      ("all")      ("all")
253      ))      ))
254    
255      
256    
257  ;; Token recognized during parsing of Ex commands (e.g., "read", "comma")  ;; Token recognized during parsing of Ex commands (e.g., "read", "comma")
258  (defvar ex-token nil)  (defvar ex-token nil)
259    
260  ;; Type of token.  ;; Type of token.
261  ;; If non-nil, gives type of address; if nil, it is a command.  ;; If non-nil, gives type of address; if nil, it is a command.
262  (defvar ex-token-type nil)  (defvar ex-token-type nil)
263    
# Line 323  Line 323 
323                ((string-match "\\(bash$\\|bash.exe$\\)" shell-file-name)                ((string-match "\\(bash$\\|bash.exe$\\)" shell-file-name)
324                 "-noprofile") ; bash: ignore .profile                 "-noprofile") ; bash: ignore .profile
325                )))                )))
326    "Options to pass to the Unix-style shell.    "Options to pass to the Unix-style shell.
327  Don't put `-c' here, as it is added automatically."  Don't put `-c' here, as it is added automatically."
328    :type '(choice (const nil) string)    :type '(choice (const nil) string)
329    :group 'viper-ex)    :group 'viper-ex)
330    
331  (defcustom ex-compile-command "make"  (defcustom ex-compile-command "make"
332    "The comand to run when the user types :make."    "The command to run when the user types :make."
333    :type 'string    :type 'string
334    :group 'viper-ex)    :group 'viper-ex)
335    
# Line 344  Don't put `-c' here, as it is added auto Line 344  Don't put `-c' here, as it is added auto
344  The default tries to set this variable to work with Unix, Windows,  The default tries to set this variable to work with Unix, Windows,
345  OS/2, and VMS.  OS/2, and VMS.
346    
347  However, if it doesn't work right for some types of Unix shells or some OS,  However, if it doesn't work right for some types of Unix shells or some OS,
348  the user should supply the appropriate function and set this variable to the  the user should supply the appropriate function and set this variable to the
349  corresponding function symbol."  corresponding function symbol."
350    :type 'symbol    :type 'symbol
# Line 370  corresponding function symbol." Line 370  corresponding function symbol."
370  ;; e.g., :r !date  ;; e.g., :r !date
371  (defvar ex-cmdfile nil)  (defvar ex-cmdfile nil)
372  (defvar ex-cmdfile-args "")  (defvar ex-cmdfile-args "")
373      
374  ;; flag used in viper-ex-read-file-name to indicate that we may be reading  ;; flag used in viper-ex-read-file-name to indicate that we may be reading
375  ;; multiple file names.  Used for :edit and :next  ;; multiple file names.  Used for :edit and :next
376  (defvar viper-keep-reading-filename nil)  (defvar viper-keep-reading-filename nil)
# Line 389  reversed." Line 389  reversed."
389    
390  ;; Last shell command executed with :! command.  ;; Last shell command executed with :! command.
391  (defvar viper-ex-last-shell-com nil)  (defvar viper-ex-last-shell-com nil)
392      
393  ;; Indicates if Minibuffer was exited temporarily in Ex-command.  ;; Indicates if Minibuffer was exited temporarily in Ex-command.
394  (defvar viper-incomplete-ex-cmd nil)  (defvar viper-incomplete-ex-cmd nil)
395      
396  ;; Remembers the last ex-command prompt.  ;; Remembers the last ex-command prompt.
397  (defvar viper-last-ex-prompt "")  (defvar viper-last-ex-prompt "")
398    
# Line 414  reversed." Line 414  reversed."
414  ;; A token has a type, \(command, address, end-mark\), and a value  ;; A token has a type, \(command, address, end-mark\), and a value
415  (defun viper-get-ex-token ()  (defun viper-get-ex-token ()
416    (save-window-excursion    (save-window-excursion
417      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
418      (set-buffer viper-ex-work-buf)      (set-buffer viper-ex-work-buf)
419      (skip-chars-forward " \t|")      (skip-chars-forward " \t|")
420      (let ((case-fold-search t))      (let ((case-fold-search t))
# Line 556  reversed." Line 556  reversed."
556                       "\\|" "![ \t]*[a-zA-Z].*"                       "\\|" "![ \t]*[a-zA-Z].*"
557                       "\\)"                       "\\)"
558                       "!*")))                       "!*")))
559            
560      (save-window-excursion ;; put cursor at the end of the Ex working buffer      (save-window-excursion ;; put cursor at the end of the Ex working buffer
561        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
562        (set-buffer viper-ex-work-buf)        (set-buffer viper-ex-work-buf)
563        (goto-char (point-max)))        (goto-char (point-max)))
564      (cond ((viper-looking-back quit-regex1) (exit-minibuffer))      (cond ((viper-looking-back quit-regex1) (exit-minibuffer))
565            ((viper-looking-back stay-regex)  (insert " "))            ((viper-looking-back stay-regex)  (insert " "))
566            ((viper-looking-back quit-regex2) (exit-minibuffer))            ((viper-looking-back quit-regex2) (exit-minibuffer))
567            (t (insert " ")))))            (t (insert " ")))))
568      
569  ;; complete Ex command  ;; complete Ex command
570  (defun ex-cmd-complete ()  (defun ex-cmd-complete ()
571    (interactive)    (interactive)
572    (let (save-pos dist compl-list string-to-complete completion-result)    (let (save-pos dist compl-list string-to-complete completion-result)
573        
574      (save-excursion      (save-excursion
575        (setq dist (skip-chars-backward "[a-zA-Z!=>&~]")        (setq dist (skip-chars-backward "[a-zA-Z!=>&~]")
576              save-pos (point)))              save-pos (point)))
577            
578      (if (or (= dist 0)      (if (or (= dist 0)
579              (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")              (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
580              (viper-looking-back              (viper-looking-back
# Line 586  reversed." Line 586  reversed."
586                  (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")                  (viper-looking-back "\\([ \t]*['`][ \t]*[a-z]*\\)")
587                  (looking-at "[^ \t\n\C-m]"))                  (looking-at "[^ \t\n\C-m]"))
588              nil              nil
589            (with-output-to-temp-buffer "*Completions*"            (with-output-to-temp-buffer "*Completions*"
590              (display-completion-list              (display-completion-list
591               (viper-alist-to-list ex-token-alist))))               (viper-alist-to-list ex-token-alist))))
592        ;; Preceding chars may be part of a command name        ;; Preceding chars may be part of a command name
593        (setq string-to-complete (buffer-substring save-pos (point)))        (setq string-to-complete (buffer-substring save-pos (point)))
594        (setq completion-result        (setq completion-result
595              (try-completion string-to-complete ex-token-alist))              (try-completion string-to-complete ex-token-alist))
596          
597        (cond ((eq completion-result t)  ; exact match--do nothing        (cond ((eq completion-result t)  ; exact match--do nothing
598               (viper-tmp-insert-at-eob " (Sole completion)"))               (viper-tmp-insert-at-eob " (Sole completion)"))
599              ((eq completion-result nil)              ((eq completion-result nil)
# Line 607  reversed." Line 607  reversed."
607                       (viper-filter-alist (concat "^" completion-result)                       (viper-filter-alist (concat "^" completion-result)
608                                         ex-token-alist)))                                         ex-token-alist)))
609               (if (> (length compl-list) 1)               (if (> (length compl-list) 1)
610                   (with-output-to-temp-buffer "*Completions*"                   (with-output-to-temp-buffer "*Completions*"
611                     (display-completion-list                     (display-completion-list
612                      (viper-alist-to-list (reverse compl-list)))))))                      (viper-alist-to-list (reverse compl-list)))))))
613        )))        )))
       
614    
615  ;; Read Ex commands  
616    ;; Read Ex commands
617  ;; ARG is a prefix argument. If given, the ex command runs on the region  ;; ARG is a prefix argument. If given, the ex command runs on the region
618  ;;(without the user having to specify the address :a,b  ;;(without the user having to specify the address :a,b
619  ;; STRING is the command to execute. If nil, then Viper asks you to enter the  ;; STRING is the command to execute. If nil, then Viper asks you to enter the
620  ;; command.  ;; command.
621  (defun viper-ex (arg &optional string)  (defun viper-ex (arg &optional string)
622    (interactive "P")    (interactive "P")
623    (or string    (or string
# Line 648  reversed." Line 648  reversed."
648                    (+ reg-beg-line (count-lines reg-beg reg-end) -1)))))                    (+ reg-beg-line (count-lines reg-beg reg-end) -1)))))
649      (if reg-beg-line      (if reg-beg-line
650          (setq initial-str (format "%d,%d" reg-beg-line reg-end-line)))          (setq initial-str (format "%d,%d" reg-beg-line reg-end-line)))
651        
652      (setq com-str      (setq com-str
653            (or string (viper-read-string-with-history            (or string (viper-read-string-with-history
654                        ":"                        ":"
655                        initial-str                        initial-str
656                        'viper-ex-history                        'viper-ex-history
657                        ;; no default when working on region                        ;; no default when working on region
# Line 663  reversed." Line 663  reversed."
663                            " [Type command to execute on current region]"))))                            " [Type command to execute on current region]"))))
664      (save-window-excursion      (save-window-excursion
665        ;; just a precaution        ;; just a precaution
666        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
667        (set-buffer viper-ex-work-buf)        (set-buffer viper-ex-work-buf)
668        (delete-region (point-min) (point-max))        (delete-region (point-min) (point-max))
669        (insert com-str "\n")        (insert com-str "\n")
# Line 718  reversed." Line 718  reversed."
718              (t (let ((ans (viper-get-ex-address-subr address dot)))              (t (let ((ans (viper-get-ex-address-subr address dot)))
719                   (if ans (setq address ans)))))                   (if ans (setq address ans)))))
720        (setq prev-token-type ex-token-type))))        (setq prev-token-type ex-token-type))))
721          
722    
723  ;; Get a regular expression and set `ex-variant', if found  ;; Get a regular expression and set `ex-variant', if found
724  ;; Viper doesn't parse the substitution or search patterns.  ;; Viper doesn't parse the substitution or search patterns.
# Line 783  reversed." Line 783  reversed."
783  ;; Get an Ex option g or c  ;; Get an Ex option g or c
784  (defun viper-get-ex-opt-gc (c)  (defun viper-get-ex-opt-gc (c)
785    (save-window-excursion    (save-window-excursion
786      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
787      (set-buffer viper-ex-work-buf)      (set-buffer viper-ex-work-buf)
788      (if (looking-at (format "%c" c)) (forward-char 1))      (if (looking-at (format "%c" c)) (forward-char 1))
789      (skip-chars-forward " \t")      (skip-chars-forward " \t")
# Line 872  reversed." Line 872  reversed."
872             (save-excursion             (save-excursion
873               (if (null ex-token)               (if (null ex-token)
874                   (exchange-point-and-mark)                   (exchange-point-and-mark)
875                 (goto-char                 (goto-char
876                  (viper-register-to-point                  (viper-register-to-point
877                   (viper-int-to-char (1+ (- ex-token ?a))) 'enforce-buffer)))                   (viper-int-to-char (1+ (- ex-token ?a))) 'enforce-buffer)))
878               (setq address (point-marker)))))               (setq address (point-marker)))))
# Line 900  reversed." Line 900  reversed."
900    (setq ex-count nil)    (setq ex-count nil)
901    (setq ex-flag nil)    (setq ex-flag nil)
902    (save-window-excursion    (save-window-excursion
903      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
904      (set-buffer viper-ex-work-buf)      (set-buffer viper-ex-work-buf)
905      (skip-chars-forward " \t")      (skip-chars-forward " \t")
906      (if (looking-at "[a-zA-Z]")      (if (looking-at "[a-zA-Z]")
# Line 926  reversed." Line 926  reversed."
926          ex-count nil          ex-count nil
927          ex-flag nil)          ex-flag nil)
928    (save-window-excursion    (save-window-excursion
929      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
930      (set-buffer viper-ex-work-buf)      (set-buffer viper-ex-work-buf)
931      (skip-chars-forward " \t")      (skip-chars-forward " \t")
932      (if (looking-at "!")      (if (looking-at "!")
# Line 952  reversed." Line 952  reversed."
952  ;; Expand \% and \# in ex command  ;; Expand \% and \# in ex command
953  (defun ex-expand-filsyms (cmd buf)  (defun ex-expand-filsyms (cmd buf)
954    (let (cf pf ret)    (let (cf pf ret)
955      (save-excursion      (save-excursion
956        (set-buffer buf)        (set-buffer buf)
957        (setq cf buffer-file-name)        (setq cf buffer-file-name)
958        (setq pf (ex-next nil t))) ; this finds alternative file name        (setq pf (ex-next nil t))) ; this finds alternative file name
# Line 966  reversed." Line 966  reversed."
966        (insert cmd)        (insert cmd)
967        (goto-char (point-min))        (goto-char (point-min))
968        (while (re-search-forward "%\\|#" nil t)        (while (re-search-forward "%\\|#" nil t)
969          (let ((data (match-data))          (let ((data (match-data))
970                (char (buffer-substring (match-beginning 0) (match-end 0))))                (char (buffer-substring (match-beginning 0) (match-end 0))))
971            (if (viper-looking-back (concat "\\\\" char))            (if (viper-looking-back (concat "\\\\" char))
972                (replace-match char)                (replace-match char)
# Line 991  reversed." Line 991  reversed."
991            ex-cmdfile-args "")            ex-cmdfile-args "")
992      (save-excursion      (save-excursion
993        (save-window-excursion        (save-window-excursion
994          (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))          (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
995          (set-buffer viper-ex-work-buf)          (set-buffer viper-ex-work-buf)
996          (skip-chars-forward " \t")          (skip-chars-forward " \t")
997          (if (looking-at "!")          (if (looking-at "!")
# Line 1052  reversed." Line 1052  reversed."
1052          (skip-chars-backward " \t\n")          (skip-chars-backward " \t\n")
1053          (setq prompt (buffer-substring (point-min) (point)))          (setq prompt (buffer-substring (point-min) (point)))
1054          ))          ))
1055        
1056      (setq viper-last-ex-prompt prompt)      (setq viper-last-ex-prompt prompt)
1057        
1058      ;; If we just finished reading command, redisplay prompt      ;; If we just finished reading command, redisplay prompt
1059      (if viper-incomplete-ex-cmd      (if viper-incomplete-ex-cmd
1060          (setq ex-file (viper-ex-read-file-name (format ":%s " prompt)))          (setq ex-file (viper-ex-read-file-name (format ":%s " prompt)))
# Line 1067  reversed." Line 1067  reversed."
1067  ;; file names, arranges to re-enter the minibuffer.  ;; file names, arranges to re-enter the minibuffer.
1068  (defun viper-complete-filename-or-exit ()  (defun viper-complete-filename-or-exit ()
1069    (interactive)    (interactive)
1070    (setq viper-keep-reading-filename t)    (setq viper-keep-reading-filename t)
1071    ;; don't exit if directory---ex-commands don't    ;; don't exit if directory---ex-commands don't
1072    (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer))    (cond ((ex-cmd-accepts-multiple-files-p ex-token) (exit-minibuffer))
1073          ;; apparently the argument to an Ex command is          ;; apparently the argument to an Ex command is
1074          ;; supposed to be a shell command          ;; supposed to be a shell command
# Line 1098  reversed." Line 1098  reversed."
1098           (minibuffer-local-completion-map           (minibuffer-local-completion-map
1099            (copy-keymap minibuffer-local-completion-map))            (copy-keymap minibuffer-local-completion-map))
1100           beg end cont val)           beg end cont val)
1101        
1102      (viper-add-keymap ex-read-filename-map      (viper-add-keymap ex-read-filename-map
1103                      (if viper-emacs-p                      (if viper-emacs-p
1104                          minibuffer-local-completion-map                          minibuffer-local-completion-map
1105                        read-file-name-map))                        read-file-name-map))
1106                        
1107      (setq cont (setq viper-keep-reading-filename t))      (setq cont (setq viper-keep-reading-filename t))
1108      (while cont      (while cont
1109        (setq viper-keep-reading-filename nil        (setq viper-keep-reading-filename nil
# Line 1114  reversed." Line 1114  reversed."
1114            (setq val (concat "\"" val "\"")))            (setq val (concat "\"" val "\"")))
1115        (setq str  (concat str (if (equal val "") "" " ")        (setq str  (concat str (if (equal val "") "" " ")
1116                           val (if (equal val "") "" " ")))                           val (if (equal val "") "" " ")))
1117                            
1118        ;; Only edit, next, and Next commands accept multiple files.        ;; Only edit, next, and Next commands accept multiple files.
1119        ;; viper-keep-reading-filename is set in the anonymous function that is        ;; viper-keep-reading-filename is set in the anonymous function that is
1120        ;; bound to " " in ex-read-filename-map.        ;; bound to " " in ex-read-filename-map.
1121        (setq cont (and viper-keep-reading-filename        (setq cont (and viper-keep-reading-filename
1122                        (ex-cmd-accepts-multiple-files-p ex-token)))                        (ex-cmd-accepts-multiple-files-p ex-token)))
1123        )        )
1124        
1125      (setq beg (string-match "[^ \t]" str)   ; delete leading blanks      (setq beg (string-match "[^ \t]" str)   ; delete leading blanks
1126            end (string-match "[ \t]*$" str)) ; delete trailing blanks            end (string-match "[ \t]*$" str)) ; delete trailing blanks
1127      (if (member ex-token '("read" "write"))      (if (member ex-token '("read" "write"))
# Line 1137  reversed." Line 1137  reversed."
1137    
1138  (defun viper-undisplayed-files ()  (defun viper-undisplayed-files ()
1139    (mapcar    (mapcar
1140     (lambda (b)     (lambda (b)
1141       (if (null (get-buffer-window b))       (if (null (get-buffer-window b))
1142           (let ((f (buffer-file-name b)))           (let ((f (buffer-file-name b)))
1143             (if f f             (if f f
1144               (if ex-cycle-through-non-files               (if ex-cycle-through-non-files
1145                   (let ((s (buffer-name b)))                   (let ((s (buffer-name b)))
1146                     (if (string= " " (substring s 0 1))                     (if (string= " " (substring s 0 1))
1147                         nil                         nil
# Line 1156  reversed." Line 1156  reversed."
1156          (args "")          (args "")
1157          (file-count 1))          (file-count 1))
1158      (while (not (null l))      (while (not (null l))
1159        (if (car l)        (if (car l)
1160            (setq args (format "%s %d) %s\n" args file-count (car l))            (setq args (format "%s %d) %s\n" args file-count (car l))
1161                  file-count (1+ file-count)))                  file-count (1+ file-count)))
1162        (setq l (cdr l)))        (setq l (cdr l)))
# Line 1260  reversed." Line 1260  reversed."
1260           (setq ex-file  (viper-abbreviate-file-name (buffer-file-name))))           (setq ex-file  (viper-abbreviate-file-name (buffer-file-name))))
1261          ((string= ex-file "")          ((string= ex-file "")
1262           (error viper-NoFileSpecified)))           (error viper-NoFileSpecified)))
1263          
1264       (let (msg do-edit)       (let (msg do-edit)
1265         (if buffer-file-name         (if buffer-file-name
1266          (cond ((buffer-modified-p)          (cond ((buffer-modified-p)
# Line 1274  reversed." Line 1274  reversed."
1274                               buffer-file-name)                               buffer-file-name)
1275                       do-edit t))                       do-edit t))
1276                (t (setq do-edit nil))))                (t (setq do-edit nil))))
1277            
1278         (if do-edit         (if do-edit
1279          (if (yes-or-no-p msg)          (if (yes-or-no-p msg)
1280              (progn              (progn
# Line 1282  reversed." Line 1282  reversed."
1282                (kill-buffer (current-buffer)))                (kill-buffer (current-buffer)))
1283            (message "Buffer %s was left intact" (buffer-name))))            (message "Buffer %s was left intact" (buffer-name))))
1284         ) ; let         ) ; let
1285      
1286    (if (null (setq file (get-file-buffer ex-file)))    (if (null (setq file (get-file-buffer ex-file)))
1287        (progn        (progn
1288          ;; this also does shell-style globbing          ;; this also does shell-style globbing
1289          (ex-find-file          (ex-find-file
1290           ;; replace # and % with the previous/current file           ;; replace # and % with the previous/current file
# Line 1296  reversed." Line 1296  reversed."
1296    (if ex-offset    (if ex-offset
1297        (progn        (progn
1298          (save-window-excursion          (save-window-excursion
1299            (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))            (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
1300            (set-buffer viper-ex-work-buf)            (set-buffer viper-ex-work-buf)
1301            (delete-region (point-min) (point-max))            (delete-region (point-min) (point-max))
1302            (insert ex-offset "\n")            (insert ex-offset "\n")
# Line 1339  reversed." Line 1339  reversed."
1339      (viper-get-ex-pat)      (viper-get-ex-pat)
1340      (if (null ex-token)      (if (null ex-token)
1341          (error "`%s': Missing regular expression" gcommand)))          (error "`%s': Missing regular expression" gcommand)))
1342      
1343    (if (string= ex-token "")    (if (string= ex-token "")
1344        (if (null viper-s-string)        (if (null viper-s-string)
1345            (error viper-NoPrevSearch)            (error viper-NoPrevSearch)
# Line 1379  reversed." Line 1379  reversed."
1379              (forward-line -1)              (forward-line -1)
1380              (end-of-line)))))              (end-of-line)))))
1381      (save-window-excursion      (save-window-excursion
1382        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
1383        (set-buffer viper-ex-work-buf)        (set-buffer viper-ex-work-buf)
1384        ;; com-str is the command string, i.e., g/pattern/ or v/pattern'        ;; com-str is the command string, i.e., g/pattern/ or v/pattern'
1385        (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))        (setq com-str (buffer-substring (1+ (point)) (1- (point-max)))))
# Line 1460  reversed." Line 1460  reversed."
1460            (error "`%s': Spurious text \"%s\" after mark name"            (error "`%s': Spurious text \"%s\" after mark name"
1461                   name (substring name 1) viper-SpuriousText))                   name (substring name 1) viper-SpuriousText))
1462      (save-window-excursion      (save-window-excursion
1463        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
1464        (set-buffer viper-ex-work-buf)        (set-buffer viper-ex-work-buf)
1465        (skip-chars-forward " \t")        (skip-chars-forward " \t")
1466        (if (looking-at "[a-z]")        (if (looking-at "[a-z]")
# Line 1475  reversed." Line 1475  reversed."
1475        (goto-char (car ex-addresses))        (goto-char (car ex-addresses))
1476        (point-to-register (viper-int-to-char (1+ (- char ?a)))))))        (point-to-register (viper-int-to-char (1+ (- char ?a)))))))
1477    
1478        
1479          
1480  ;; Alternate file is the file next to the first one in the buffer ring  ;; Alternate file is the file next to the first one in the buffer ring
1481  (defun ex-next (cycle-other-window &optional find-alt-file)  (defun ex-next (cycle-other-window &optional find-alt-file)
1482    (catch 'ex-edit    (catch 'ex-edit
1483      (let (count l)      (let (count l)
1484        (if (not find-alt-file)        (if (not find-alt-file)
1485            (progn            (progn
1486              (viper-get-ex-file)              (viper-get-ex-file)
1487              (if (or (char-or-string-p ex-offset)              (if (or (char-or-string-p ex-offset)
1488                      (and (not (string= "" ex-file))                      (and (not (string= "" ex-file))
1489                           (not (string-match "^[0-9]+$" ex-file))))                           (not (string-match "^[0-9]+$" ex-file))))
1490                  (progn                  (progn
1491                    (ex-edit t)                    (ex-edit t)
# Line 1515  reversed." Line 1515  reversed."
1515    
1516    
1517  (defun ex-next-related-buffer (direction &optional no-recursion)  (defun ex-next-related-buffer (direction &optional no-recursion)
1518      
1519    (viper-ring-rotate1 viper-related-files-and-buffers-ring direction)    (viper-ring-rotate1 viper-related-files-and-buffers-ring direction)
1520      
1521    (let ((file-or-buffer-name    (let ((file-or-buffer-name
1522           (viper-current-ring-item viper-related-files-and-buffers-ring))           (viper-current-ring-item viper-related-files-and-buffers-ring))
1523          (old-ring viper-related-files-and-buffers-ring)          (old-ring viper-related-files-and-buffers-ring)
1524          (old-win (selected-window))          (old-win (selected-window))
1525          skip-rest buf wind)          skip-rest buf wind)
1526        
1527      (or (and (ring-p viper-related-files-and-buffers-ring)      (or (and (ring-p viper-related-files-and-buffers-ring)
1528               (> (ring-length viper-related-files-and-buffers-ring) 0))               (> (ring-length viper-related-files-and-buffers-ring) 0))
1529          (error "This buffer has no related files or buffers"))          (error "This buffer has no related files or buffers"))
1530            
1531      (or (stringp file-or-buffer-name)      (or (stringp file-or-buffer-name)
1532          (error          (error
1533           "File and buffer names must be strings, %S" file-or-buffer-name))           "File and buffer names must be strings, %S" file-or-buffer-name))
1534        
1535      (setq buf (cond ((get-buffer file-or-buffer-name))      (setq buf (cond ((get-buffer file-or-buffer-name))
1536                      ((file-exists-p file-or-buffer-name)                      ((file-exists-p file-or-buffer-name)
1537                       (find-file-noselect file-or-buffer-name))                       (find-file-noselect file-or-buffer-name))
1538                      ))                      ))
1539        
1540      (if (not (viper-buffer-live-p buf))      (if (not (viper-buffer-live-p buf))
1541          (error "Didn't find buffer %S or file %S"          (error "Didn't find buffer %S or file %S"
1542                 file-or-buffer-name                 file-or-buffer-name
1543                 (viper-abbreviate-file-name                 (viper-abbreviate-file-name
1544                  (expand-file-name file-or-buffer-name))))                  (expand-file-name file-or-buffer-name))))
1545              
1546      (if (equal buf (current-buffer))      (if (equal buf (current-buffer))
1547          (or no-recursion          (or no-recursion
1548              ;; try again              ;; try again
1549              (progn              (progn
1550                (setq skip-rest t)                (setq skip-rest t)
1551                (ex-next-related-buffer direction 'norecursion))))                (ex-next-related-buffer direction 'norecursion))))
1552            
1553      (if skip-rest      (if skip-rest
1554          ()          ()
1555        ;; setup buffer        ;; setup buffer
# Line 1557  reversed." Line 1557  reversed."
1557            ()            ()
1558          (setq wind (get-lru-window (if viper-xemacs-p nil 'visible)))          (setq wind (get-lru-window (if viper-xemacs-p nil 'visible)))
1559          (set-window-buffer wind buf))          (set-window-buffer wind buf))
1560                
1561        (if (viper-window-display-p)        (if (viper-window-display-p)
1562            (progn            (progn
1563              (raise-frame (window-frame wind))              (raise-frame (window-frame wind))
# Line 1565  reversed." Line 1565  reversed."
1565                  (save-window-excursion (select-window wind) (sit-for 1))                  (save-window-excursion (select-window wind) (sit-for 1))
1566                (select-window wind)))                (select-window wind)))
1567          (save-window-excursion (select-window wind) (sit-for 1)))          (save-window-excursion (select-window wind) (sit-for 1)))
1568            
1569        (save-excursion        (save-excursion
1570          (set-buffer buf)          (set-buffer buf)
1571          (setq viper-related-files-and-buffers-ring old-ring))          (setq viper-related-files-and-buffers-ring old-ring))
1572          
1573        (setq viper-local-search-start-marker (point-marker))        (setq viper-local-search-start-marker (point-marker))
1574        )))        )))
1575      
1576        
1577  ;; Force auto save  ;; Force auto save
1578  (defun ex-preserve ()  (defun ex-preserve ()
1579    (message "Autosaving all buffers that need to be saved...")    (message "Autosaving all buffers that need to be saved...")
# Line 1595  reversed." Line 1595  reversed."
1595  (defun ex-quit ()  (defun ex-quit ()
1596    ;; skip "!", if it is q!.  In Viper q!, w!, etc., behave as q, w, etc.    ;; skip "!", if it is q!.  In Viper q!, w!, etc., behave as q, w, etc.
1597    (save-excursion    (save-excursion
1598      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
1599      (set-buffer viper-ex-work-buf)      (set-buffer viper-ex-work-buf)
1600      (if (looking-at "!") (forward-char 1)))      (if (looking-at "!") (forward-char 1)))
1601    (if (< viper-expert-level 3)    (if (< viper-expert-level 3)
# Line 1621  reversed." Line 1621  reversed."
1621            (setq ex-file buffer-file-name)))            (setq ex-file buffer-file-name)))
1622      (if ex-cmdfile      (if ex-cmdfile
1623          (progn          (progn
1624            (setq command            (setq command
1625                  ;; replace # and % with the previous/current file                  ;; replace # and % with the previous/current file
1626                  (ex-expand-filsyms (concat ex-file ex-cmdfile-args)                  (ex-expand-filsyms (concat ex-file ex-cmdfile-args)
1627                                     (current-buffer)))                                     (current-buffer)))
1628            (shell-command command t))            (shell-command command t))
1629        (insert-file-contents ex-file)))        (insert-file-contents ex-file)))
1630    (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args))    (ex-fixup-history viper-last-ex-prompt ex-file ex-cmdfile-args))
1631      
1632  ;; this function fixes ex-history for some commands like ex-read, ex-edit  ;; this function fixes ex-history for some commands like ex-read, ex-edit
1633  (defun ex-fixup-history (&rest args)    (defun ex-fixup-history (&rest args)
1634    (setq viper-ex-history    (setq viper-ex-history
1635          (cons (mapconcat 'identity args " ") (cdr viper-ex-history))))          (cons (mapconcat 'identity args " ") (cdr viper-ex-history))))
1636      
1637    
1638  ;; Ex recover from emacs \#file\#  ;; Ex recover from emacs \#file\#
1639  (defun ex-recover ()  (defun ex-recover ()
# Line 1674  reversed." Line 1674  reversed."
1674            (viper-set-unread-command-events ?\C-m)))            (viper-set-unread-command-events ?\C-m)))
1675      (message ":set  <Variable> [= <Value>]")      (message ":set  <Variable> [= <Value>]")
1676      (or batch (sit-for 2))      (or batch (sit-for 2))
1677        
1678      (while (string-match "^[ \\t\\n]*$"      (while (string-match "^[ \\t\\n]*$"
1679                           (setq str                           (setq str
1680                                 (completing-read ":set " ex-variable-alist)))                                 (completing-read ":set " ex-variable-alist)))
# Line 1755  reversed." Line 1755  reversed."
1755            (or (viper-set-unread-command-events "") (sit-for 2))            (or (viper-set-unread-command-events "") (sit-for 2))
1756            (setq val (read-string (format ":set %s = " var)))            (setq val (read-string (format ":set %s = " var)))
1757            (ex-fixup-history "set" orig-var val)            (ex-fixup-history "set" orig-var val)
1758              
1759            ;; check numerical values            ;; check numerical values
1760            (if (member var            (if (member var
1761                        '("sw" "shiftwidth"                        '("sw" "shiftwidth"
1762                          "ts" "tabstop"                          "ts" "tabstop"
1763                          "ts-g" "tabstop-global"                          "ts-g" "tabstop-global"
1764                          "wm" "wrapmargin"))                          "wm" "wrapmargin"))
1765                (condition-case nil                (condition-case nil
1766                    (or (numberp (setq val2 (car (read-from-string val))))                    (or (numberp (setq val2 (car (read-from-string val))))
1767                        (error "%s: Invalid value, numberp, %S" var val))                        (error "%s: Invalid value, numberp, %S" var val))
1768                  (error                  (error
1769                   (error "%s: Invalid value, numberp, %S" var val))))                   (error "%s: Invalid value, numberp, %S" var val))))
1770                      
1771            (cond            (cond
1772             ((member var '("sw" "shiftwidth"))             ((member var '("sw" "shiftwidth"))
1773              (setq var "viper-shift-width"))              (setq var "viper-shift-width"))
# Line 1782  reversed." Line 1782  reversed."
1782                    set-cmd "setq-default"))                    set-cmd "setq-default"))
1783             ((member var '("wm" "wrapmargin"))             ((member var '("wm" "wrapmargin"))
1784              ;; make it take effect in curr buff and new bufs              ;; make it take effect in curr buff and new bufs
1785              (kill-local-variable 'fill-column)              (kill-local-variable 'fill-column)
1786              (setq var "fill-column"              (setq var "fill-column"
1787                    val (format "(- (window-width) %s)" val)                    val (format "(- (window-width) %s)" val)
1788                    set-cmd "setq-default"))                    set-cmd "setq-default"))
1789             ((member var '("sh" "shell"))             ((member var '("sh" "shell"))
1790              (setq var "explicit-shell-file-name"              (setq var "explicit-shell-file-name"
1791                    val (format "\"%s\"" val)))))                    val (format "\"%s\"" val)))))
1792        (ex-fixup-history "set" orig-var))        (ex-fixup-history "set" orig-var))
1793        
1794      (if set-cmd      (if set-cmd
1795          (setq actual-lisp-cmd          (setq actual-lisp-cmd
1796                (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label)                (format "\n(%s %s %s) %s" set-cmd var val auto-cmd-label)
1797                lisp-cmd-del-pattern                lisp-cmd-del-pattern
1798                (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"                (format "^\n?[ \t]*([ \t]*%s[ \t]+%s[ \t].*)[ \t]*%s"
1799                        set-cmd var auto-cmd-label)))                        set-cmd var auto-cmd-label)))
1800        
1801      (if (and ask-if-save      (if (and ask-if-save
1802               (y-or-n-p (format "Do you want to save this setting in %s "               (y-or-n-p (format "Do you want to save this setting in %s "
1803                                 viper-custom-file-name)))                                 viper-custom-file-name)))
1804          (progn          (progn
1805            (viper-save-string-in-file            (viper-save-string-in-file
1806             actual-lisp-cmd viper-custom-file-name             actual-lisp-cmd viper-custom-file-name
1807             ;; del pattern             ;; del pattern
1808             lisp-cmd-del-pattern)             lisp-cmd-del-pattern)
# Line 1822  reversed." Line 1822  reversed."
1822                   lisp-cmd-del-pattern)                   lisp-cmd-del-pattern)
1823                  ))                  ))
1824            ))            ))
1825        
1826      (if set-cmd      (if set-cmd
1827          (message "%s %s %s"          (message "%s %s %s"
1828                   set-cmd var                   set-cmd var
# Line 1843  reversed." Line 1843  reversed."
1843  ;; special meaning  ;; special meaning
1844  (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)  (defun ex-get-inline-cmd-args (regex-forw &optional chars-back replace-str)
1845    (save-excursion    (save-excursion
1846      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))      (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
1847      (set-buffer viper-ex-work-buf)      (set-buffer viper-ex-work-buf)
1848      (goto-char (point-min))      (goto-char (point-min))
1849      (re-search-forward regex-forw nil t)      (re-search-forward regex-forw nil t)
# Line 1868  reversed." Line 1868  reversed."
1868  ;; Ex shell command  ;; Ex shell command
1869  (defun ex-shell ()  (defun ex-shell ()
1870    (shell))    (shell))
1871      
1872  ;; Viper help.  Invokes Info  ;; Viper help.  Invokes Info
1873  (defun ex-help ()  (defun ex-help ()
1874    (condition-case nil    (condition-case nil
# Line 1895  Please contact your system administrator Line 1895  Please contact your system administrator
1895    
1896  ;; Ex substitute command  ;; Ex substitute command
1897  ;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string  ;; If REPEAT use previous regexp which is ex-reg-exp or viper-s-string
1898  (defun ex-substitute (&optional repeat r-flag)  (defun ex-substitute (&optional repeat r-flag)
1899    (let ((opt-g nil)    (let ((opt-g nil)
1900          (opt-c nil)          (opt-c nil)
1901          (matched-pos nil)          (matched-pos nil)
# Line 1993  Please contact your system administrator Line 1993  Please contact your system administrator
1993  (defun ex-tag ()  (defun ex-tag ()
1994    (let (tag)    (let (tag)
1995      (save-window-excursion      (save-window-excursion
1996        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
1997        (set-buffer viper-ex-work-buf)        (set-buffer viper-ex-work-buf)
1998        (skip-chars-forward " \t")        (skip-chars-forward " \t")
1999        (set-mark (point))        (set-mark (point))
# Line 2013  Please contact your system administrator Line 2013  Please contact your system administrator
2013    
2014  ;; Ex write command  ;; Ex write command
2015  ;; ex-write doesn't support wildcards, because file completion is a better  ;; ex-write doesn't support wildcards, because file completion is a better
2016  ;; mechanism. We also don't support # and %  ;; mechanism. We also don't support # and %
2017  ;; because file history is a better mechanism.  ;; because file history is a better mechanism.
2018  (defun ex-write (q-flag)  (defun ex-write (q-flag)
2019    (viper-default-ex-addresses t)    (viper-default-ex-addresses t)
2020    (viper-get-ex-file)    (viper-get-ex-file)
2021    (let ((end (car ex-addresses))    (let ((end (car ex-addresses))
2022          (beg (car (cdr ex-addresses)))          (beg (car (cdr ex-addresses)))
2023          (orig-buf (current-buffer))          (orig-buf (current-buffer))
2024          ;;(orig-buf-file-name (buffer-file-name))          ;;(orig-buf-file-name (buffer-file-name))
2025          ;;(orig-buf-name (buffer-name))          ;;(orig-buf-name (buffer-name))
# Line 2030  Please contact your system administrator Line 2030  Please contact your system administrator
2030      (if ex-cmdfile      (if ex-cmdfile
2031          (progn          (progn
2032            (viper-enlarge-region beg end)            (viper-enlarge-region beg end)
2033            (shell-command-on-region (point) (mark t)            (shell-command-on-region (point) (mark t)
2034                                     (concat ex-file ex-cmdfile-args)))                                     (concat ex-file ex-cmdfile-args)))
2035        (if (and (string= ex-file "") (not (buffer-file-name)))        (if (and (string= ex-file "") (not (buffer-file-name)))
2036            (setq ex-file            (setq ex-file
2037                  (read-file-name                  (read-file-name
2038                   (format "Buffer %s isn't visiting any file.  File to save in: "                   (format "Buffer %s isn't visiting any file.  File to save in: "
2039                           (buffer-name)))))                           (buffer-name)))))
2040          
2041        (setq writing-whole-file (and (= (point-min) beg) (= (point-max) end))        (setq writing-whole-file (and (= (point-min) beg) (= (point-max) end))
2042              ex-file (if (string= ex-file "")              ex-file (if (string= ex-file "")
2043                          (buffer-file-name)                          (buffer-file-name)
# Line 2049  Please contact your system administrator Line 2049  Please contact your system administrator
2049            (setq ex-file            (setq ex-file
2050                  (concat (file-name-as-directory ex-file)                  (concat (file-name-as-directory ex-file)
2051                          (file-name-nondirectory buffer-file-name))))                          (file-name-nondirectory buffer-file-name))))
2052          
2053        (setq file-exists (file-exists-p ex-file)        (setq file-exists (file-exists-p ex-file)
2054              writing-same-file (string= ex-file (buffer-file-name)))              writing-same-file (string= ex-file (buffer-file-name)))
2055    
# Line 2070  Please contact your system administrator Line 2070  Please contact your system administrator
2070                         (format "File %s exists.  Overwrite? " ex-file))))                         (format "File %s exists.  Overwrite? " ex-file))))
2071              (error "Quit"))              (error "Quit"))
2072          ;; writing a region or whole buffer to non-visited file          ;; writing a region or whole buffer to non-visited file
2073          (unwind-protect          (unwind-protect
2074              (save-excursion              (save-excursion
2075                (viper-enlarge-region beg end)                (viper-enlarge-region beg end)
2076                (setq region (buffer-substring (point) (mark t)))                (setq region (buffer-substring (point) (mark t)))
# Line 2104  Please contact your system administrator Line 2104  Please contact your system administrator
2104        (if (and (buffer-file-name) writing-same-file)        (if (and (buffer-file-name) writing-same-file)
2105            (set-visited-file-modtime))            (set-visited-file-modtime))
2106        ;; prevent loss of data if saving part of the buffer in visited file        ;; prevent loss of data if saving part of the buffer in visited file
2107        (or writing-whole-file        (or writing-whole-file
2108            (not writing-same-file)            (not writing-same-file)
2109            (progn            (progn
2110              (sit-for 2)              (sit-for 2)
# Line 2115  Please contact your system administrator Line 2115  Please contact your system administrator
2115                (save-buffers-kill-emacs)                (save-buffers-kill-emacs)
2116              (kill-buffer (current-buffer))))              (kill-buffer (current-buffer))))
2117        )))        )))
2118              
2119    
2120  (defun ex-write-info (exists file-name beg end)  (defun ex-write-info (exists file-name beg end)
2121    (message "`%s'%s %d lines, %d characters"    (message "`%s'%s %d lines, %d characters"
# Line 2155  Please contact your system administrator Line 2155  Please contact your system administrator
2155  (defun ex-command ()  (defun ex-command ()
2156    (let (command)    (let (command)
2157      (save-window-excursion      (save-window-excursion
2158        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))        (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
2159        (set-buffer viper-ex-work-buf)        (set-buffer viper-ex-work-buf)
2160        (skip-chars-forward " \t")        (skip-chars-forward " \t")
2161        (setq command (buffer-substring (point) (point-max)))        (setq command (buffer-substring (point) (point-max)))
# Line 2262  Type 'mak ' (including the space) to run Line 2262  Type 'mak ' (including the space) to run
2262    (with-output-to-temp-buffer " *viper-info*"    (with-output-to-temp-buffer " *viper-info*"
2263      (princ (if viper-auto-indent      (princ (if viper-auto-indent
2264                 "autoindent (local)\n" "noautoindent (local)\n"))                 "autoindent (local)\n" "noautoindent (local)\n"))
2265      (princ (if (default-value 'viper-auto-indent)      (princ (if (default-value 'viper-auto-indent)
2266                 "autoindent (global) \n" "noautoindent (global) \n"))                 "autoindent (global) \n" "noautoindent (global) \n"))
2267      (princ (if viper-case-fold-search "ignorecase\n" "noignorecase\n"))      (princ (if viper-case-fold-search "ignorecase\n" "noignorecase\n"))
2268      (princ (if viper-re-search "magic\n" "nomagic\n"))      (princ (if viper-re-search "magic\n" "nomagic\n"))

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.44.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26