Mercurial > emacs
comparison lisp/emulation/viper-cmd.el @ 82467:ff85cbd27ee2
2007-08-19 Michael Kifer <kifer@cs.stonybrook.edu>
* viper.el (viper-remove-hooks): remove some additional viper hooks
when the user calls viper-go-away.
(viper-go-away): restore the default of default-major-mode.
Save the value of default-major-mode before vaperization.
* viper-cmd.el: Replace error "" with "Viper bell".
* viper-ex.el: Replace error "" with "Viper bell".
* ediff-util.el (ediff-make-temp-file): use the coding system of the
buffer for which file is created.
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Sun, 19 Aug 2007 13:47:08 +0000 |
parents | b98604865ea0 |
children | d505125b0b46 aaccdab0ee26 |
comparison
equal
deleted
inserted
replaced
82466:168363a0236b | 82467:ff85cbd27ee2 |
---|---|
1114 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. | 1114 ;; interpret these keys in Emacs mode, so ESC won't be interpreted as a Vi key. |
1115 (defun viper-intercept-ESC-key () | 1115 (defun viper-intercept-ESC-key () |
1116 "Function that implements ESC key in Viper emulation of Vi." | 1116 "Function that implements ESC key in Viper emulation of Vi." |
1117 (interactive) | 1117 (interactive) |
1118 (let ((cmd (or (key-binding (viper-envelop-ESC-key)) | 1118 (let ((cmd (or (key-binding (viper-envelop-ESC-key)) |
1119 '(lambda () (interactive) (error ""))))) | 1119 '(lambda () (interactive) (error "Viper bell"))))) |
1120 | 1120 |
1121 ;; call the actual function to execute ESC (if no other symbols followed) | 1121 ;; call the actual function to execute ESC (if no other symbols followed) |
1122 ;; or the key bound to the ESC sequence (if the sequence was issued | 1122 ;; or the key bound to the ESC sequence (if the sequence was issued |
1123 ;; with very short delay between characters). | 1123 ;; with very short delay between characters). |
1124 (if (eq cmd 'viper-intercept-ESC-key) | 1124 (if (eq cmd 'viper-intercept-ESC-key) |
1236 ;; this means that we already have a command character, so we | 1236 ;; this means that we already have a command character, so we |
1237 ;; construct a com list and exit while. however, if char is " | 1237 ;; construct a com list and exit while. however, if char is " |
1238 ;; it is an error. | 1238 ;; it is an error. |
1239 (progn | 1239 (progn |
1240 ;; new com is (CHAR . OLDCOM) | 1240 ;; new com is (CHAR . OLDCOM) |
1241 (if (viper-memq-char char '(?# ?\")) (error "")) | 1241 (if (viper-memq-char char '(?# ?\")) (error "Viper bell")) |
1242 (setq com (cons char com)) | 1242 (setq com (cons char com)) |
1243 (setq cont nil)) | 1243 (setq cont nil)) |
1244 ;; If com is nil we set com as char, and read more. Again, if char is | 1244 ;; If com is nil we set com as char, and read more. Again, if char is |
1245 ;; ", we read the name of register and store it in viper-use-register. | 1245 ;; ", we read the name of register and store it in viper-use-register. |
1246 ;; if char is !, =, or #, a complete com is formed so we exit the while | 1246 ;; if char is !, =, or #, a complete com is formed so we exit the while |
1255 (setq char (read-char))) | 1255 (setq char (read-char))) |
1256 ((viper= char ?\") | 1256 ((viper= char ?\") |
1257 (let ((reg (read-char))) | 1257 (let ((reg (read-char))) |
1258 (if (viper-valid-register reg) | 1258 (if (viper-valid-register reg) |
1259 (setq viper-use-register reg) | 1259 (setq viper-use-register reg) |
1260 (error "")) | 1260 (error "Viper bell")) |
1261 (setq char (read-char)))) | 1261 (setq char (read-char)))) |
1262 (t | 1262 (t |
1263 (setq com char) | 1263 (setq com char) |
1264 (setq char (read-char)))))) | 1264 (setq char (read-char)))))) |
1265 | 1265 |
1277 (or (viper-movement-command-p char) | 1277 (or (viper-movement-command-p char) |
1278 (viper-digit-command-p char) | 1278 (viper-digit-command-p char) |
1279 (viper-regsuffix-command-p char) | 1279 (viper-regsuffix-command-p char) |
1280 (viper= char ?!) ; bang command | 1280 (viper= char ?!) ; bang command |
1281 (viper= char ?g) ; the gg command (like G0) | 1281 (viper= char ?g) ; the gg command (like G0) |
1282 (error "")) | 1282 (error "Viper bell")) |
1283 (setq cmd-to-exec-at-end | 1283 (setq cmd-to-exec-at-end |
1284 (viper-exec-form-in-vi | 1284 (viper-exec-form-in-vi |
1285 `(key-binding (char-to-string ,char))))) | 1285 `(key-binding (char-to-string ,char))))) |
1286 | 1286 |
1287 ;; as com is non-nil, this means that we have a command to execute | 1287 ;; as com is non-nil, this means that we have a command to execute |
1311 ((equal com '(?> . ?>)) (viper-line (cons value ?>))) | 1311 ((equal com '(?> . ?>)) (viper-line (cons value ?>))) |
1312 ((equal com '(?! . ?!)) (viper-line (cons value ?!))) | 1312 ((equal com '(?! . ?!)) (viper-line (cons value ?!))) |
1313 ((equal com '(?= . ?=)) (viper-line (cons value ?=))) | 1313 ((equal com '(?= . ?=)) (viper-line (cons value ?=))) |
1314 ;; gg acts as G0 | 1314 ;; gg acts as G0 |
1315 ((equal (car com) ?g) (viper-goto-line 0)) | 1315 ((equal (car com) ?g) (viper-goto-line 0)) |
1316 (t (error ""))))) | 1316 (t (error "Viper bell"))))) |
1317 | 1317 |
1318 (if cmd-to-exec-at-end | 1318 (if cmd-to-exec-at-end |
1319 (progn | 1319 (progn |
1320 (setq last-command-char char) | 1320 (setq last-command-char char) |
1321 (setq last-command-event | 1321 (setq last-command-event |
2736 ;; forward-char may be the parameter of a delete, and 'dl' works | 2736 ;; forward-char may be the parameter of a delete, and 'dl' works |
2737 ;; just like 'x' for the last char on a line, so we have to allow | 2737 ;; just like 'x' for the last char on a line, so we have to allow |
2738 ;; the forward motion before the 'viper-execute-com', but, of | 2738 ;; the forward motion before the 'viper-execute-com', but, of |
2739 ;; course, 'dl' doesn't work on an empty line, so we have to | 2739 ;; course, 'dl' doesn't work on an empty line, so we have to |
2740 ;; catch that condition before 'viper-execute-com' | 2740 ;; catch that condition before 'viper-execute-com' |
2741 (if (and (eolp) (bolp)) (error "") (forward-char val)) | 2741 (if (and (eolp) (bolp)) (error "Viper bell") (forward-char val)) |
2742 (if com (viper-execute-com 'viper-forward-char val com)) | 2742 (if com (viper-execute-com 'viper-forward-char val com)) |
2743 (if (eolp) (progn (backward-char 1) (error "")))) | 2743 (if (eolp) (progn (backward-char 1) (error "Viper bell")))) |
2744 (forward-char val) | 2744 (forward-char val) |
2745 (if com (viper-execute-com 'viper-forward-char val com))))) | 2745 (if com (viper-execute-com 'viper-forward-char val com))))) |
2746 | 2746 |
2747 | 2747 |
2748 (defun viper-backward-char (arg) | 2748 (defun viper-backward-char (arg) |
2753 (let ((val (viper-p-val arg)) | 2753 (let ((val (viper-p-val arg)) |
2754 (com (viper-getcom arg))) | 2754 (com (viper-getcom arg))) |
2755 (if com (viper-move-marker-locally 'viper-com-point (point))) | 2755 (if com (viper-move-marker-locally 'viper-com-point (point))) |
2756 (if viper-ex-style-motion | 2756 (if viper-ex-style-motion |
2757 (progn | 2757 (progn |
2758 (if (bolp) (error "") (backward-char val)) | 2758 (if (bolp) (error "Viper bell") (backward-char val)) |
2759 (if com (viper-execute-com 'viper-backward-char val com))) | 2759 (if com (viper-execute-com 'viper-backward-char val com))) |
2760 (backward-char val) | 2760 (backward-char val) |
2761 (if com (viper-execute-com 'viper-backward-char val com))))) | 2761 (if com (viper-execute-com 'viper-backward-char val com))))) |
2762 | 2762 |
2763 | 2763 |
3076 (while (> (current-column) (1- val)) | 3076 (while (> (current-column) (1- val)) |
3077 (backward-char 1)) | 3077 (backward-char 1)) |
3078 (if com (viper-execute-com 'viper-goto-col val com)) | 3078 (if com (viper-execute-com 'viper-goto-col val com)) |
3079 (save-excursion | 3079 (save-excursion |
3080 (end-of-line) | 3080 (end-of-line) |
3081 (if (> val (current-column)) (error ""))) | 3081 (if (> val (current-column)) (error "Viper bell"))) |
3082 )) | 3082 )) |
3083 | 3083 |
3084 | 3084 |
3085 (defun viper-next-line (arg) | 3085 (defun viper-next-line (arg) |
3086 "Go to next line." | 3086 "Go to next line." |
3196 | 3196 |
3197 ;; Find ARG's occurrence of CHAR on the current line. | 3197 ;; Find ARG's occurrence of CHAR on the current line. |
3198 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to | 3198 ;; If FORWARD then search is forward, otherwise backward. OFFSET is used to |
3199 ;; adjust point after search. | 3199 ;; adjust point after search. |
3200 (defun viper-find-char (arg char forward offset) | 3200 (defun viper-find-char (arg char forward offset) |
3201 (or (char-or-string-p char) (error "")) | 3201 (or (char-or-string-p char) (error "Viper bell")) |
3202 (let ((arg (if forward arg (- arg))) | 3202 (let ((arg (if forward arg (- arg))) |
3203 (cmd (if (eq viper-intermediate-command 'viper-repeat) | 3203 (cmd (if (eq viper-intermediate-command 'viper-repeat) |
3204 (nth 5 viper-d-com) | 3204 (nth 5 viper-d-com) |
3205 (viper-array-to-string (this-command-keys)))) | 3205 (viper-array-to-string (this-command-keys)))) |
3206 point region-beg region-end) | 3206 point region-beg region-end) |
3542 ((looking-at "[])}]") | 3542 ((looking-at "[])}]") |
3543 (forward-char) | 3543 (forward-char) |
3544 (if com (viper-move-marker-locally 'viper-com-point (point))) | 3544 (if com (viper-move-marker-locally 'viper-com-point (point))) |
3545 (backward-sexp 1) | 3545 (backward-sexp 1) |
3546 (if com (viper-execute-com 'viper-paren-match nil com))) | 3546 (if com (viper-execute-com 'viper-paren-match nil com))) |
3547 (t (error "")))))) | 3547 (t (error "Viper bell")))))) |
3548 | 3548 |
3549 (defun viper-toggle-parse-sexp-ignore-comments () | 3549 (defun viper-toggle-parse-sexp-ignore-comments () |
3550 (interactive) | 3550 (interactive) |
3551 (setq viper-parse-sexp-ignore-comments | 3551 (setq viper-parse-sexp-ignore-comments |
3552 (not viper-parse-sexp-ignore-comments)) | 3552 (not viper-parse-sexp-ignore-comments)) |
4105 (if (null text) | 4105 (if (null text) |
4106 (if viper-use-register | 4106 (if viper-use-register |
4107 (let ((reg viper-use-register)) | 4107 (let ((reg viper-use-register)) |
4108 (setq viper-use-register nil) | 4108 (setq viper-use-register nil) |
4109 (error viper-EmptyRegister reg)) | 4109 (error viper-EmptyRegister reg)) |
4110 (error ""))) | 4110 (error "Viper bell"))) |
4111 (setq viper-use-register nil) | 4111 (setq viper-use-register nil) |
4112 (if (viper-end-with-a-newline-p text) | 4112 (if (viper-end-with-a-newline-p text) |
4113 (progn | 4113 (progn |
4114 (end-of-line) | 4114 (end-of-line) |
4115 (if (eobp) | 4115 (if (eobp) |
4155 (if (null text) | 4155 (if (null text) |
4156 (if viper-use-register | 4156 (if viper-use-register |
4157 (let ((reg viper-use-register)) | 4157 (let ((reg viper-use-register)) |
4158 (setq viper-use-register nil) | 4158 (setq viper-use-register nil) |
4159 (error viper-EmptyRegister reg)) | 4159 (error viper-EmptyRegister reg)) |
4160 (error ""))) | 4160 (error "Viper bell"))) |
4161 (setq viper-use-register nil) | 4161 (setq viper-use-register nil) |
4162 (if (viper-end-with-a-newline-p text) (beginning-of-line)) | 4162 (if (viper-end-with-a-newline-p text) (beginning-of-line)) |
4163 (viper-set-destructive-command | 4163 (viper-set-destructive-command |
4164 (list 'viper-Put-back val nil viper-use-register nil nil)) | 4164 (list 'viper-Put-back val nil viper-use-register nil nil)) |
4165 (set-marker (viper-mark-marker) (point) (current-buffer)) | 4165 (set-marker (viper-mark-marker) (point) (current-buffer)) |
4200 (list 'viper-delete-char val nil nil nil nil)) | 4200 (list 'viper-delete-char val nil nil nil nil)) |
4201 (if (and viper-ex-style-editing | 4201 (if (and viper-ex-style-editing |
4202 (> val (viper-chars-in-region (point) (viper-line-pos 'end)))) | 4202 (> val (viper-chars-in-region (point) (viper-line-pos 'end)))) |
4203 (setq val (viper-chars-in-region (point) (viper-line-pos 'end)))) | 4203 (setq val (viper-chars-in-region (point) (viper-line-pos 'end)))) |
4204 (if (and viper-ex-style-motion (eolp)) | 4204 (if (and viper-ex-style-motion (eolp)) |
4205 (if (bolp) (error "") (setq val 0))) ; not bol---simply back 1 ch | 4205 (if (bolp) (error "Viper bell") (setq val 0))) ; not bol---simply back 1 ch |
4206 (save-excursion | 4206 (save-excursion |
4207 (viper-forward-char-carefully val) | 4207 (viper-forward-char-carefully val) |
4208 (setq end-del-pos (point))) | 4208 (setq end-del-pos (point))) |
4209 (if viper-use-register | 4209 (if viper-use-register |
4210 (progn | 4210 (progn |
4465 ((viper= char ?>) (viper-mark-end-of-buffer)) | 4465 ((viper= char ?>) (viper-mark-end-of-buffer)) |
4466 ((viper= char ?.) (viper-set-mark-if-necessary)) | 4466 ((viper= char ?.) (viper-set-mark-if-necessary)) |
4467 ((viper= char ?,) (viper-cycle-through-mark-ring)) | 4467 ((viper= char ?,) (viper-cycle-through-mark-ring)) |
4468 ((viper= char ?^) (push-mark viper-saved-mark t t)) | 4468 ((viper= char ?^) (push-mark viper-saved-mark t t)) |
4469 ((viper= char ?D) (mark-defun)) | 4469 ((viper= char ?D) (mark-defun)) |
4470 (t (error "")) | 4470 (t (error "Viper bell")) |
4471 ))) | 4471 ))) |
4472 | 4472 |
4473 ;; Algorithm: If first invocation of this command save mark on ring, goto | 4473 ;; Algorithm: If first invocation of this command save mark on ring, goto |
4474 ;; mark, M0, and pop the most recent elt from the mark ring into mark, | 4474 ;; mark, M0, and pop the most recent elt from the mark ring into mark, |
4475 ;; making it into the new mark, M1. | 4475 ;; making it into the new mark, M1. |
4564 'viper-goto-mark) | 4564 'viper-goto-mark) |
4565 nil com) | 4565 nil com) |
4566 (switch-to-buffer buff) | 4566 (switch-to-buffer buff) |
4567 (goto-char viper-com-point) | 4567 (goto-char viper-com-point) |
4568 (viper-change-state-to-vi) | 4568 (viper-change-state-to-vi) |
4569 (error ""))))) | 4569 (error "Viper bell"))))) |
4570 ((and (not skip-white) (viper= char ?`)) | 4570 ((and (not skip-white) (viper= char ?`)) |
4571 (if com (viper-move-marker-locally 'viper-com-point (point))) | 4571 (if com (viper-move-marker-locally 'viper-com-point (point))) |
4572 (if (and (viper-same-line (point) viper-last-jump) | 4572 (if (and (viper-same-line (point) viper-last-jump) |
4573 (= (point) viper-last-jump-ignore)) | 4573 (= (point) viper-last-jump-ignore)) |
4574 (goto-char viper-last-jump)) | 4574 (goto-char viper-last-jump)) |