comparison lisp/view.el @ 109853:fe07c47cf7a7

merge and fixes
author Joakim <joakim@localhost.localdomain>
date Thu, 13 May 2010 15:13:52 +0200
parents 0b37f86b040e
children 417b1e4d63cd
comparison
equal deleted inserted replaced
109852:e56f669f17ce 109853:fe07c47cf7a7
159 159
160 (defvar view-overlay nil 160 (defvar view-overlay nil
161 "Overlay used to display where a search operation found its match. 161 "Overlay used to display where a search operation found its match.
162 This is local in each buffer, once it is used.") 162 This is local in each buffer, once it is used.")
163 (make-variable-buffer-local 'view-overlay) 163 (make-variable-buffer-local 'view-overlay)
164
165 (unless (assq 'view-mode minor-mode-alist)
166 (setq minor-mode-alist
167 (cons (list 'view-mode
168 (propertize " View"
169 'local-map mode-line-minor-mode-keymap
170 'help-echo "mouse-3: minor mode menu"))
171 minor-mode-alist)))
172 164
173 ;; Define keymap inside defvar to make it easier to load changes. 165 ;; Define keymap inside defvar to make it easier to load changes.
174 ;; Some redundant "less"-like key bindings below have been commented out. 166 ;; Some redundant "less"-like key bindings below have been commented out.
175 (defvar view-mode-map 167 (defvar view-mode-map
176 (let ((map (make-sparse-keymap))) 168 (let ((map (make-sparse-keymap)))
228 (define-key map "0" 'digit-argument) 220 (define-key map "0" 'digit-argument)
229 (define-key map "H" 'describe-mode) 221 (define-key map "H" 'describe-mode)
230 (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above. 222 (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above.
231 (define-key map "h" 'describe-mode) 223 (define-key map "h" 'describe-mode)
232 map)) 224 map))
233
234 (or (assq 'view-mode minor-mode-map-alist)
235 (setq minor-mode-map-alist
236 (cons (cons 'view-mode view-mode-map) minor-mode-map-alist)))
237 225
238 ;;; Commands that enter or exit view mode. 226 ;;; Commands that enter or exit view mode.
239 227
240 ;; This is used when view mode is exited, to make sure we don't try to 228 ;; This is used when view mode is exited, to make sure we don't try to
241 ;; kill a buffer modified by the user. A buffer in view mode can 229 ;; kill a buffer modified by the user. A buffer in view mode can
260 This command runs the normal hook `view-mode-hook'." 248 This command runs the normal hook `view-mode-hook'."
261 (interactive "fView file: ") 249 (interactive "fView file: ")
262 (unless (file-exists-p file) (error "%s does not exist" file)) 250 (unless (file-exists-p file) (error "%s does not exist" file))
263 (let ((had-a-buf (get-file-buffer file)) 251 (let ((had-a-buf (get-file-buffer file))
264 (buffer (find-file-noselect file))) 252 (buffer (find-file-noselect file)))
265 (if (eq (with-current-buffer buffer 253 (view-buffer buffer (and (not had-a-buf) 'kill-buffer-if-not-modified))))
266 (get major-mode 'mode-class))
267 'special)
268 (progn
269 (switch-to-buffer buffer)
270 (message "Not using View mode because the major mode is special"))
271 (view-buffer buffer (and (not had-a-buf) 'kill-buffer-if-not-modified)))))
272 254
273 ;;;###autoload 255 ;;;###autoload
274 (defun view-file-other-window (file) 256 (defun view-file-other-window (file)
275 "View FILE in View mode in another window. 257 "View FILE in View mode in another window.
276 When done, return that window to its previous buffer, and kill the 258 When done, return that window to its previous buffer, and kill the
332 Do not set EXIT-ACTION to `kill-buffer' when BUFFER visits a 314 Do not set EXIT-ACTION to `kill-buffer' when BUFFER visits a
333 file: Users may suspend viewing in order to modify the buffer. 315 file: Users may suspend viewing in order to modify the buffer.
334 Exiting View mode will then discard the user's edits. Setting 316 Exiting View mode will then discard the user's edits. Setting
335 EXIT-ACTION to `kill-buffer-if-not-modified' avoids this." 317 EXIT-ACTION to `kill-buffer-if-not-modified' avoids this."
336 (interactive "bView buffer: ") 318 (interactive "bView buffer: ")
337 (let ((undo-window (list (window-buffer) (window-start) (window-point)))) 319 (if (eq (with-current-buffer buffer
338 (switch-to-buffer buffer) 320 (get major-mode 'mode-class))
339 (view-mode-enter (cons (selected-window) (cons nil undo-window)) 321 'special)
340 exit-action))) 322 (progn
323 (switch-to-buffer buffer)
324 (message "Not using View mode because the major mode is special"))
325 (let ((undo-window (list (window-buffer) (window-start) (window-point))))
326 (switch-to-buffer buffer)
327 (view-mode-enter (cons (selected-window) (cons nil undo-window))
328 exit-action))))
341 329
342 ;;;###autoload 330 ;;;###autoload
343 (defun view-buffer-other-window (buffer &optional not-return exit-action) 331 (defun view-buffer-other-window (buffer &optional not-return exit-action)
344 "View BUFFER in View mode in another window. 332 "View BUFFER in View mode in another window.
345 Return to previous buffer when done, unless optional NOT-RETURN is 333 Return to previous buffer when done, unless optional NOT-RETURN is
391 (switch-to-buffer-other-frame buffer) 379 (switch-to-buffer-other-frame buffer)
392 (view-mode-enter (and return-to (cons (selected-window) return-to)) 380 (view-mode-enter (and return-to (cons (selected-window) return-to))
393 exit-action))) 381 exit-action)))
394 382
395 ;;;###autoload 383 ;;;###autoload
396 (defun view-mode (&optional arg) 384 (define-minor-mode view-mode
397 ;; In the following documentation string we have to use some explicit key 385 ;; In the following documentation string we have to use some explicit key
398 ;; bindings instead of using the \\[] construction. The reason for this 386 ;; bindings instead of using the \\[] construction. The reason for this
399 ;; is that most commands have more than one key binding. 387 ;; is that most commands have more than one key binding.
400 "Toggle View mode, a minor mode for viewing text but not editing it. 388 "Toggle View mode, a minor mode for viewing text but not editing it.
401 With prefix argument ARG, turn View mode on if ARG is positive, otherwise 389 With prefix argument ARG, turn View mode on if ARG is positive, otherwise
471 \\[view-buffer-other-window], \\[view-buffer-other frame], \\[view-file], 459 \\[view-buffer-other-window], \\[view-buffer-other frame], \\[view-file],
472 \\[view-file-other-window], or \\[view-file-other-frame], 460 \\[view-file-other-window], or \\[view-file-other-frame],
473 then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to that buffer. 461 then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to that buffer.
474 462
475 Entry to view-mode runs the normal hook `view-mode-hook'." 463 Entry to view-mode runs the normal hook `view-mode-hook'."
476 (interactive "P") 464 :lighter " View" :keymap view-mode-map
477 (unless (and arg ; Do nothing if already OK. 465 (if view-mode (view-mode-enable) (view-mode-disable)))
478 (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode)))
479 (if view-mode (view-mode-disable)
480 (view-mode-enable))))
481 466
482 (defun view-mode-enable () 467 (defun view-mode-enable ()
483 "Turn on View mode." 468 "Turn on View mode."
484 ;; Always leave view mode before changing major mode. 469 ;; Always leave view mode before changing major mode.
485 ;; This is to guarantee that the buffer-read-only variable is restored. 470 ;; This is to guarantee that the buffer-read-only variable is restored.