comparison lisp/emulation/viper-cmd.el @ 74857:2e5f946f7726

2006-12-23 Michael Kifer <kifer@cs.stonybrook.edu> * ediff-diff.el (ediff-diff-options): clarify docstring. (ediff-setup-diff-regions): disallow -u in ediff-diff-options. * viper-cmd.el (viper-post-command-sentinel): protect against errors in hooks. (viper-add-newline-at-eob-if-necessary): add newline only if we actually modify buffer; ignore errors if occur.
author Michael Kifer <kifer@cs.stonybrook.edu>
date Sat, 23 Dec 2006 21:33:50 +0000
parents db25befb2938
children 7a3f13e2dd57 bc10a33dd40b
comparison
equal deleted inserted replaced
74856:333882884f8a 74857:2e5f946f7726
169 ;; Runs viper-before-change-functions inside before-change-functions 169 ;; Runs viper-before-change-functions inside before-change-functions
170 (defun viper-before-change-sentinel (beg end) 170 (defun viper-before-change-sentinel (beg end)
171 (run-hook-with-args 'viper-before-change-functions beg end)) 171 (run-hook-with-args 'viper-before-change-functions beg end))
172 172
173 (defsubst viper-post-command-sentinel () 173 (defsubst viper-post-command-sentinel ()
174 (run-hooks 'viper-post-command-hooks) 174 (condition-case conds
175 (run-hooks 'viper-post-command-hooks)
176 (error (viper-message-conditions conds)))
175 (if (eq viper-current-state 'vi-state) 177 (if (eq viper-current-state 'vi-state)
176 (viper-restore-cursor-color 'after-insert-mode))) 178 (viper-restore-cursor-color 'after-insert-mode)))
177 179
178 (defsubst viper-pre-command-sentinel () 180 (defsubst viper-pre-command-sentinel ()
179 (run-hooks 'viper-pre-command-hooks)) 181 (run-hooks 'viper-pre-command-hooks))
924 result) 926 result)
925 (viper-set-mode-vars-for 'vi-state) 927 (viper-set-mode-vars-for 'vi-state)
926 928
927 (condition-case nil 929 (condition-case nil
928 (let (viper-vi-kbd-minor-mode) ; execute without kbd macros 930 (let (viper-vi-kbd-minor-mode) ; execute without kbd macros
929 (setq result (eval form)) 931 (setq result (eval form)))
930 )
931 (error 932 (error
932 (signal 'quit nil))) 933 (signal 'quit nil)))
933 934
934 (if (not (equal buff (current-buffer))) ; cmd switched buffer 935 (if (not (equal buff (current-buffer))) ; cmd switched buffer
935 (save-excursion 936 (save-excursion
1969 (save-restriction 1970 (save-restriction
1970 (widen) 1971 (widen)
1971 (if (and (eobp) 1972 (if (and (eobp)
1972 (not (bolp)) 1973 (not (bolp))
1973 require-final-newline 1974 require-final-newline
1975 ;; add newline only if we actually edited buffer. otherwise it
1976 ;; might unintentionally modify binary buffers
1977 (buffer-modified-p)
1974 (not (viper-is-in-minibuffer)) 1978 (not (viper-is-in-minibuffer))
1975 (not buffer-read-only)) 1979 (not buffer-read-only))
1976 (insert "\n"))) 1980 ;; text property may be read-only
1981 (condition-case nil
1982 (insert "\n")
1983 (error nil))
1984 ))
1977 )) 1985 ))
1978 1986
1979 (defun viper-yank-defun () 1987 (defun viper-yank-defun ()
1980 (mark-defun) 1988 (mark-defun)
1981 (copy-region-as-kill (point) (mark t))) 1989 (copy-region-as-kill (point) (mark t)))