From: Martin Rudalics Date: Sat, 19 Jan 2008 16:29:08 +0000 (+0000) Subject: (hide-ifdef-shadow): New option. X-Git-Tag: emacs-pretest-23.0.90~8499 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f3a221cf73ddcb68d168d2a3e81c4ad60881525e;p=emacs.git (hide-ifdef-shadow): New option. (hide-ifdef-shadow): New face. (hide-ifdef-toggle-shadowing): New function to toggle between shadowing and making code invisible. (hide-ifdef-mode-submap): Add binding for hide-ifdef-toggle-shadowing. (hide-ifdef-mode-menu): Add entry for hide-ifdef-toggle-shadowing. (hide-ifdef-region-internal): Give new overlay hide-ifdef property. Shadow text when hide-ifdef-shadow is non-nil. (hif-show-ifdef-region): Remove overlays with hide-ifdef property set. (hif-hide-line): Use when instead of if. (hide-ifdef-initially, hide-ifdef-read-only, hide-ifdef-lines): Remove unneeded * from doc-strings. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b3f873c73e3..cab7c60b452 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,21 @@ +2008-01-19 Martin Rudalics + + * progmodes/hideif.el (hide-ifdef-shadow): New option. + (hide-ifdef-shadow): New face. + (hide-ifdef-toggle-shadowing): New function to toggle between + shadowing and making code invisible. + (hide-ifdef-mode-submap): Add binding for + hide-ifdef-toggle-shadowing. + (hide-ifdef-mode-menu): Add entry for + hide-ifdef-toggle-shadowing. + (hide-ifdef-region-internal): Give new overlay hide-ifdef + property. Shadow text when hide-ifdef-shadow is non-nil. + (hif-show-ifdef-region): Remove overlays with hide-ifdef + property set. + (hif-hide-line): Use when instead of if. + (hide-ifdef-initially, hide-ifdef-read-only, hide-ifdef-lines): + Remove unneeded * from doc-strings. + 2008-01-19 Stefan Monnier * doc-view.el (doc-view-goto-page): Don't move point any more, now that diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el index 126b5310ccc..0d2bf1a656a 100644 --- a/lisp/progmodes/hideif.el +++ b/lisp/progmodes/hideif.el @@ -128,6 +128,7 @@ (define-key map "\C-s" 'show-ifdef-block) (define-key map "\C-q" 'hide-ifdef-toggle-read-only) + (define-key map "\C-w" 'hide-ifdef-toggle-shadowing) (substitute-key-definition 'toggle-read-only 'hide-ifdef-toggle-outside-read-only map) map) @@ -155,7 +156,9 @@ ["Use an alist" hide-ifdef-use-define-alist t] ["Undefine a variable" hide-ifdef-undef t] ["Toggle read only" hide-ifdef-toggle-read-only - :style toggle :selected hide-ifdef-read-only])) + :style toggle :selected hide-ifdef-read-only] + ["Toggle shadowing" hide-ifdef-toggle-shadowing + :style toggle :selected hide-ifdef-shadow])) (defvar hide-ifdef-hiding nil "Non-nil when text may be hidden.") @@ -256,9 +259,12 @@ how the hiding is done: (end-of-line 2))) (defun hide-ifdef-region-internal (start end) - (remove-overlays start end 'invisible 'hide-ifdef) + (remove-overlays start end 'hide-ifdef t) (let ((o (make-overlay start end))) - (overlay-put o 'invisible 'hide-ifdef))) + (overlay-put o 'hide-ifdef t) + (if hide-ifdef-shadow + (overlay-put o 'face 'hide-ifdef-shadow) + (overlay-put o 'invisible 'hide-ifdef)))) (defun hide-ifdef-region (start end) "START is the start of a #if or #else form. END is the ending part. @@ -270,7 +276,7 @@ Everything including these lines is made invisible." (defun hif-show-ifdef-region (start end) "Everything between START and END is made visible." - (remove-overlays start end 'invisible 'hide-ifdef)) + (remove-overlays start end 'hide-ifdef t)) ;;===%%SF%% evaluation (Start) === @@ -740,11 +746,11 @@ Point is left unchanged." (defun hif-hide-line (point) "Hide the line containing point. Does nothing if `hide-ifdef-lines' is nil." - (if hide-ifdef-lines - (save-excursion - (goto-char point) - (hide-ifdef-region-internal (line-beginning-position) - (progn (hif-end-of-line) (point)))))) + (when hide-ifdef-lines + (save-excursion + (goto-char point) + (hide-ifdef-region-internal + (line-beginning-position) (progn (hif-end-of-line) (point)))))) ;;; Hif-Possibly-Hide @@ -829,22 +835,33 @@ It does not do the work that's pointless to redo on a recursive entry." ;;;###autoload (defcustom hide-ifdef-initially nil - "*Non-nil means call `hide-ifdefs' when Hide-Ifdef mode is first activated." + "Non-nil means call `hide-ifdefs' when Hide-Ifdef mode is first activated." :type 'boolean :group 'hide-ifdef) ;;;###autoload (defcustom hide-ifdef-read-only nil - "*Set to non-nil if you want buffer to be read-only while hiding text." + "Set to non-nil if you want buffer to be read-only while hiding text." :type 'boolean :group 'hide-ifdef) ;;;###autoload (defcustom hide-ifdef-lines nil - "*Non-nil means hide the #ifX, #else, and #endif lines." + "Non-nil means hide the #ifX, #else, and #endif lines." + :type 'boolean + :group 'hide-ifdef) + +;;;###autoload +(defcustom hide-ifdef-shadow nil + "Non-nil means shadow text instead of hiding it." :type 'boolean :group 'hide-ifdef) +;;;###autoload +(defface hide-ifdef-shadow '((t (:inherit shadow))) + "Face for shadowing ifdef blocks." + :group 'hide-ifdef) + (defun hide-ifdef-toggle-read-only () "Toggle `hide-ifdef-read-only'." (interactive) @@ -866,6 +883,21 @@ It does not do the work that's pointless to redo on a recursive entry." hif-outside-read-only)) (force-mode-line-update)) +(defun hide-ifdef-toggle-shadowing () + "Toggle shadowing." + (interactive) + (set (make-local-variable 'hide-ifdef-shadow) (not hide-ifdef-shadow)) + (message "Shadowing %s" (if hide-ifdef-shadow "ON" "OFF")) + (save-restriction + (widen) + (dolist (overlay (overlays-in (point-min) (point-max))) + (when (overlay-get overlay 'hide-ifdef) + (if hide-ifdef-shadow + (progn + (overlay-put overlay 'invisible nil) + (overlay-put overlay 'face 'hide-ifdef-shadow)) + (overlay-put overlay 'face nil) + (overlay-put overlay 'invisible 'hide-ifdef)))))) (defun hide-ifdef-define (var) "Define a VAR so that #ifdef VAR would be included."