Mercurial > emacs
changeset 7324:7e78d145539b
(show-ifdefs, hide-ifdefs): Bind inhibit-read-only.
Set buffer-read-only directly.
(hide-ifdef-block): Likewise.
(show-ifdef-block): Bind inhibit-read-only; don't set buffer-read-only.
Delete bindings for C-c C-f, C-c C-b, C-c C-u, C-c C-d,
C-c C-p and C-c C-n. Move C-c C-h to C-c C-d.
(define-hide-ifdef-mode-map): Remove this code
from a function and execute it at load time.
(hide-ifdef-mode-submap): New variable holds the list of commands.
(hide-ifdef-mode-map): Set this up with a prefix key
and put it in minor-mode-map-alist.
(hide-ifdef-mode-map-before): Variable deleted.
(hide-ifdef-mode): Use force-mode-line-update.
Delete the code to manipulate keymaps.
(define-hide-ifdef-mode-map):
Pass (keymap) as KEYMAP arg to where-is-internal.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 04 May 1994 23:20:44 +0000 |
parents | 5399c72e0dde |
children | bfbebc2a04c9 |
files | lisp/progmodes/hideif.el |
diffstat | 1 files changed, 53 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/progmodes/hideif.el Wed May 04 22:44:55 1994 +0000 +++ b/lisp/progmodes/hideif.el Wed May 04 23:20:44 1994 +0000 @@ -1,8 +1,9 @@ ;;; hide-ifdef-mode.el --- hides selected code within ifdef. -;;; Copyright (C) 1988 Free Software Foundation, Inc. +;;; Copyright (C) 1988, 1994 Free Software Foundation, Inc. ;; Author: Dan LaLiberte <liberte@a.cs.uiuc.edu> +;; Maintainer: FSF ;; Keywords: c ;; This file is part of GNU Emacs. @@ -140,55 +141,59 @@ ;;; Code: +(defvar hide-ifdef-mode-submap nil + "Keymap used with Hide-Ifdef mode.") + (defvar hide-ifdef-mode-map nil - "Keymap used with Hide-Ifdef mode") + "Keymap used with Hide-Ifdef mode.") (defconst hide-ifdef-mode-prefix-key "\C-c" "Prefix key for all Hide-Ifdef mode commands.") -(defvar hide-ifdef-mode-map-before nil - "Buffer-local variable to store a copy of the local keymap -before `hide-ifdef-mode' modifies it.") +;; Set up the submap that goes after the prefix key. +(if hide-ifdef-mode-submap + () ; dont redefine it. + (setq hide-ifdef-mode-submap (make-sparse-keymap)) + (define-key hide-ifdef-mode-submap "\ed" 'hide-ifdef-define) + (define-key hide-ifdef-mode-submap "\eu" 'hide-ifdef-undef) + (define-key hide-ifdef-mode-submap "\eD" 'hide-ifdef-set-define-alist) + (define-key hide-ifdef-mode-submap "\eU" 'hide-ifdef-use-define-alist) + + (define-key hide-ifdef-mode-submap "\eh" 'hide-ifdefs) + (define-key hide-ifdef-mode-submap "\es" 'show-ifdefs) + (define-key hide-ifdef-mode-submap "\C-d" 'hide-ifdef-block) + (define-key hide-ifdef-mode-submap "\C-s" 'show-ifdef-block) -(defun define-hide-ifdef-mode-map () - (if hide-ifdef-mode-map - () ; dont redefine it. - (setq hide-ifdef-mode-map (make-sparse-keymap)) - (define-key hide-ifdef-mode-map "\ed" 'hide-ifdef-define) - (define-key hide-ifdef-mode-map "\eu" 'hide-ifdef-undef) - (define-key hide-ifdef-mode-map "\eD" 'hide-ifdef-set-define-alist) - (define-key hide-ifdef-mode-map "\eU" 'hide-ifdef-use-define-alist) - - (define-key hide-ifdef-mode-map "\eh" 'hide-ifdefs) - (define-key hide-ifdef-mode-map "\es" 'show-ifdefs) - (define-key hide-ifdef-mode-map "\C-h" 'hide-ifdef-block) - (define-key hide-ifdef-mode-map "\C-s" 'show-ifdef-block) - - (define-key hide-ifdef-mode-map "\C-f" 'forward-ifdef) - (define-key hide-ifdef-mode-map "\C-b" 'backward-ifdef) - (define-key hide-ifdef-mode-map "\C-d" 'down-ifdef) - (define-key hide-ifdef-mode-map "\C-u" 'up-ifdef) - (define-key hide-ifdef-mode-map "\C-n" 'next-ifdef) - (define-key hide-ifdef-mode-map "\C-p" 'previous-ifdef) - (define-key hide-ifdef-mode-map "\C-q" 'hide-ifdef-toggle-read-only) - (let ((where (where-is-internal 'toggle-read-only nil nil t))) - (if where - (define-key hide-ifdef-mode-map - where - 'hide-ifdef-toggle-outside-read-only))) - ) - (fset 'hide-ifdef-mode-map hide-ifdef-mode-map) ; the function is the map + (define-key hide-ifdef-mode-submap "\C-q" 'hide-ifdef-toggle-read-only) + (let ((where (where-is-internal 'toggle-read-only '(keymap) t))) + (if where + (define-key hide-ifdef-mode-submap + where + 'hide-ifdef-toggle-outside-read-only))) ) +;; Set up the mode's main map, which leads via the prefix key to the submap. +(if hide-ifdef-mode-map + () + (setq hide-ifdef-mode-map (make-sparse-keymap)) + (define-key hide-ifdef-mode-map hide-ifdef-mode-prefix-key + hide-ifdef-mode-submap)) + (defun hif-update-mode-line () "Update mode-line by setting buffer-modified to itself." (set-buffer-modified-p (buffer-modified-p))) (defvar hide-ifdef-mode nil - "non-nil when hide-ifdef-mode is activated.") + "Non-nil when hide-ifdef-mode is activated.") (defvar hide-ifdef-hiding nil - "non-nil when text may be hidden.") + "Non-nil when text may be hidden.") + +;; Arrange to use the mode's map when the mode is enabled. +(or (assq 'hide-ifdef-mode minor-mode-map-alist) + (setq minor-mode-map-alist + (cons (cons hide-ifdef-mode hide-ifdef-mode-map) + minor-mode-map-alist))) (or (assq 'hide-ifdef-hiding minor-mode-alist) (setq minor-mode-alist @@ -240,7 +245,7 @@ (not hide-ifdef-mode) (> (prefix-numeric-value arg) 0))) - (hif-update-mode-line) + (force-mode-line-update) (if hide-ifdef-mode (progn @@ -259,13 +264,6 @@ (make-local-variable 'hif-outside-read-only) (setq hif-outside-read-only buffer-read-only) - (make-local-variable 'hide-ifdef-mode-map-before) - (setq hide-ifdef-mode-map-before (current-local-map)) - (use-local-map (copy-keymap (current-local-map))) - (local-unset-key hide-ifdef-mode-prefix-key) - (local-set-key hide-ifdef-mode-prefix-key 'hide-ifdef-mode-map) - (define-hide-ifdef-mode-map) - (run-hooks 'hide-ifdef-mode-hook) (if hide-ifdef-initially @@ -276,7 +274,6 @@ ; else end hide-ifdef-mode (if hide-ifdef-hiding (show-ifdefs)) - (use-local-map hide-ifdef-mode-map-before) (message "Exit hide-ifdef-mode.") )) @@ -922,23 +919,21 @@ (hide-ifdef-mode 1)) ; turn on hide-ifdef-mode (if hide-ifdef-hiding (show-ifdefs)) ; Otherwise, deep confusion. - (if buffer-read-only (toggle-read-only)) ; make it writable temporarily - (setq selective-display t) - (setq hide-ifdef-hiding t) - (hide-ifdef-guts) - (if (or hide-ifdef-read-only hif-outside-read-only) - (toggle-read-only)) ; make it read only + (let ((inhibit-read-only t)) + (setq selective-display t) + (setq hide-ifdef-hiding t) + (hide-ifdef-guts)) + (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only)) (message "Hiding done")) (defun show-ifdefs () "Cancel the effects of `hide-ifdef'. The contents of all #ifdefs is shown." (interactive) - (if buffer-read-only (toggle-read-only)) ; make it writable temporarily + (setq buffer-read-only hif-outside-read-only) (setq selective-display nil) ; defaults - (hif-show-all) - (if hif-outside-read-only - (toggle-read-only)) ; make it read only + (let ((inhibit-read-only t)) + (hif-show-all)) (setq hide-ifdef-hiding nil)) @@ -969,9 +964,8 @@ (interactive) (if (not hide-ifdef-mode) (hide-ifdef-mode 1)) - (if buffer-read-only (toggle-read-only)) (setq selective-display t) - (let (top bottom) + (let (top bottom (inhibit-read-only t)) (hif-find-ifdef-block) ; set top and bottom - dynamic scoping (hide-ifdef-region top bottom) (if hide-ifdef-lines @@ -979,15 +973,13 @@ (hif-hide-line top) (hif-hide-line (1+ bottom)))) (setq hide-ifdef-hiding t)) - (if (or hide-ifdef-read-only hif-outside-read-only) - (toggle-read-only))) + (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) (defun show-ifdef-block () "Show the ifdef block (true or false part) enclosing or before the cursor." (interactive) - (let ((old-read-only buffer-read-only)) - (if old-read-only (toggle-read-only)) + (let ((inhibit-read-only t)) (if hide-ifdef-lines (save-excursion (beginning-of-line) @@ -995,11 +987,7 @@ (let (top bottom) (hif-find-ifdef-block) - (hif-show-ifdef-region (1- top) bottom)) - ) - - ; restore read only status since we dont know if all is shown. - (if old-read-only (toggle-read-only)))) + (hif-show-ifdef-region (1- top) bottom))))) ;;; definition alist support