;;; hideif.el --- hides selected code within ifdef
-;; Copyright (C) 1988, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;; 2008 Free Software Foundation, Inc.
;; Author: Daniel LaLiberte <liberte@holonexus.org>
;; Maintainer: FSF
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; M-x hide-ifdefs or C-c @ h
;;
;; Hide-ifdef suppresses the display of code that the preprocessor wouldn't
-;; pass through. The support of constant expressions in #if lines is
+;; pass through. The support of constant expressions in #if lines is
;; limited to identifiers, parens, and the operators: &&, ||, !, and
;; "defined". Please extend this.
;;
;; still in the buffer, and you can move the point into it and modify
;; text unawares.
;; You can make your buffer read-only while hide-ifdef-hiding by setting
-;; hide-ifdef-read-only to a non-nil value. You can toggle this
+;; hide-ifdef-read-only to a non-nil value. You can toggle this
;; variable with hide-ifdef-toggle-read-only (C-c @ C-q).
;;
;; You can undo the effect of hide-ifdefs by typing
;; If you define or undefine a symbol while hide-ifdef-mode is in effect,
;; the display will be updated. Only the define list for the current
;; buffer will be affected. You can save changes to the local define
-;; list with hide-ifdef-set-define-alist. This adds entries
+;; list with hide-ifdef-set-define-alist. This adds entries
;; to hide-ifdef-define-alist.
;;
;; If you have defined a hide-ifdef-mode-hook, you can set
;;
;; Written by Brian Marick, at Gould, Computer Systems Division, Urbana IL.
;; Extensively modified by Daniel LaLiberte (while at Gould).
-;;
-;; You may freely modify and distribute this, but keep a record
-;; of modifications and send comments to:
-;; liberte@a.cs.uiuc.edu or ihnp4!uiucdcs!liberte
-;; I will continue to upgrade hide-ifdef-mode
-;; with your contributions.
;;; Code:
"Hide selected code within `ifdef'."
:group 'c)
+(defcustom hide-ifdef-initially nil
+ "Non-nil means call `hide-ifdefs' when Hide-Ifdef mode is first activated."
+ :type 'boolean
+ :group 'hide-ifdef)
+
+(defcustom hide-ifdef-read-only nil
+ "Set to non-nil if you want buffer to be read-only while hiding text."
+ :type 'boolean
+ :group 'hide-ifdef)
+
+(defcustom hide-ifdef-lines nil
+ "Non-nil means hide the #ifX, #else, and #endif lines."
+ :type 'boolean
+ :group 'hide-ifdef)
+
+(defcustom hide-ifdef-shadow nil
+ "Non-nil means shadow text instead of hiding it."
+ :type 'boolean
+ :group 'hide-ifdef
+ :version "23.1")
+
+(defface hide-ifdef-shadow '((t (:inherit shadow)))
+ "Face for shadowing ifdef blocks."
+ :group 'hide-ifdef
+ :version "23.1")
+
+
(defvar hide-ifdef-mode-submap
;; Set up the submap that goes after the prefix key.
(let ((map (make-sparse-keymap)))
(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)
map)
"Keymap used with `hide-ifdef-mode'.")
+(easy-menu-define hide-ifdef-mode-menu hide-ifdef-mode-map
+ "Menu for `hide-ifdef-mode'."
+ '("Hide-Ifdef"
+ ["Hide some ifdefs" hide-ifdefs
+ :help "Hide the contents of some #ifdefs"]
+ ["Show all ifdefs" show-ifdefs
+ :help "Cancel the effects of `hide-ifdef': show the contents of all #ifdefs"]
+ ["Hide ifdef block" hide-ifdef-block
+ :help "Hide the ifdef block (true or false part) enclosing or before the cursor"]
+ ["Show ifdef block" show-ifdef-block
+ :help "Show the ifdef block (true or false part) enclosing or before the cursor"]
+ ["Define a variable..." hide-ifdef-define
+ :help "Define a VAR so that #ifdef VAR would be included"]
+ ["Undefine a variable..." hide-ifdef-undef
+ :help "Undefine a VAR so that #ifdef VAR would not be included"]
+ ["Define an alist..." hide-ifdef-set-define-alist
+ :help "Set the association for NAME to `hide-ifdef-env'"]
+ ["Use an alist..." hide-ifdef-use-define-alist
+ :help "Set `hide-ifdef-env' to the define list specified by NAME"]
+ ["Toggle read only" hide-ifdef-toggle-read-only
+ :style toggle :selected hide-ifdef-read-only
+ :help "Buffer should be read-only while hiding text"]
+ ["Toggle shadowing" hide-ifdef-toggle-shadowing
+ :style toggle :selected hide-ifdef-shadow
+ :help "Text should be shadowed instead of hidden"]))
+
(defvar hide-ifdef-hiding nil
"Non-nil when text may be hidden.")
is used.
`hide-ifdef-define-alist'
- An association list of defined symbol lists.
+ An association list of defined symbol lists.
Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env'
and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env'
from one of the lists in `hide-ifdef-define-alist'.
After `show-ifdefs', read-only status is restored to previous value.
\\{hide-ifdef-mode-map}"
- nil " Ifdef" nil
+ :group 'hide-ifdef :lighter " Ifdef"
(if hide-ifdef-mode
(progn
;; inherit global values
(set (make-local-variable 'hide-ifdef-hiding)
(default-value 'hide-ifdef-hiding))
(set (make-local-variable 'hif-outside-read-only) buffer-read-only)
+ (set (make-local-variable 'line-move-ignore-invisible) t)
+ (add-hook 'change-major-mode-hook
+ (lambda () (hide-ifdef-mode -1)) nil t)
(add-to-invisibility-spec '(hide-ifdef . t))
(hide-ifdefs)
(show-ifdefs)))
;; else end hide-ifdef-mode
- (if hide-ifdef-hiding
- (show-ifdefs))))
-
+ (kill-local-variable 'line-move-ignore-invisible)
+ (remove-from-invisibility-spec '(hide-ifdef . t))
+ (when hide-ifdef-hiding
+ (show-ifdefs))))
+
(defun hif-show-all ()
"Show all of the text in the current buffer."
(hide-ifdefs t)))
(add-hook 'after-revert-hook 'hif-after-revert-function)
+(defun hif-end-of-line ()
+ (end-of-line)
+ (while (= (logand 1 (skip-chars-backward "\\\\")) 1)
+ (end-of-line 2)))
+
+(defun hide-ifdef-region-internal (start end)
+ (remove-overlays start end 'hide-ifdef t)
+ (let ((o (make-overlay start end)))
+ (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.
Everything including these lines is made invisible."
(save-excursion
- (goto-char start) (end-of-line) (setq start (point))
- (goto-char end) (end-of-line) (setq end (point))
- (remove-overlays start end 'invisible 'hide-ifdef)
- (let ((o (make-overlay start end)))
- (overlay-put o 'invisible 'hide-ifdef))))
+ (goto-char start) (hif-end-of-line) (setq start (point))
+ (goto-char end) (hif-end-of-line) (setq end (point))
+ (hide-ifdef-region-internal start end)))
(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) ===
hif-undefined-symbol)))
(defun hif-defined (var)
- (hif-lookup var)
- ;; when #if expressions are fully supported, defined result should be 1
- ;; (if (assoc var hide-ifdef-env)
- ;; 1
- ;; nil)
- )
-
+ (if (assoc var hide-ifdef-env) 1 0))
;;===%%SF%% evaluation (End) ===
(defvar hif-token)
(defvar hif-token-list)
-(defun hif-infix-to-prefix (token-list)
- "Convert list of tokens in infix into prefix list."
- ;; (message "hif-infix-to-prefix: %s" token-list)
- (if (= 1 (length token-list))
- `(hif-lookup (quote ,(car token-list)))
- (hif-parse-if-exp token-list)))
-
-;; pattern to match initial identifier, !, &&, ||, (, or ).
-;; Added ==, + and -: garyo@avs.com 8/9/94
-(defconst hif-token-regexp "^\\(&&\\|||\\|[!=]=\\|!\\|[()+-]\\|[<>]=?\\|\\w+\\)")
-(defconst hif-end-of-comment "\\*/")
-
-
-(defun hif-tokenize (expr-string)
- "Separate string into a list of tokens."
- (let ((token-list nil)
- (expr-start 0)
- (expr-length (length expr-string)))
+(defconst hif-token-alist
+ '(("||" . or)
+ ("&&" . and)
+ ("|" . hif-logior)
+ ("&" . hif-logand)
+ ("==" . equal)
+ ("!=" . hif-notequal)
+ ("!" . not)
+ ("(" . lparen)
+ (")" . rparen)
+ (">" . hif-greater)
+ ("<" . hif-less)
+ (">=" . hif-greater-equal)
+ ("<=" . hif-less-equal)
+ ("+" . hif-plus)
+ ("-" . hif-minus)
+ ("?" . hif-conditional)
+ (":" . hif-colon)))
+
+(defconst hif-token-regexp
+ (concat (regexp-opt (mapcar 'car hif-token-alist)) "\\|\\w+"))
+
+(defun hif-tokenize (start end)
+ "Separate string between START and END into a list of tokens."
+ (let ((token-list nil))
(with-syntax-table hide-ifdef-syntax-table
- (while (< expr-start expr-length)
- ;; (message "expr-start = %d" expr-start) (sit-for 1)
- (cond
- ((string-match "^[ \t]+" expr-string expr-start)
- ;; skip whitespace
- (setq expr-start (match-end 0))
- ;; stick newline in string so ^ matches on the next string-match
- (aset expr-string (1- expr-start) ?\n))
-
- ((string-match "^/\\*" expr-string expr-start)
- (setq expr-start (match-end 0))
- (aset expr-string (1- expr-start) ?\n)
- (or
- (string-match hif-end-of-comment
- expr-string expr-start) ; eat comment
- (string-match "$" expr-string expr-start)) ; multi-line comment
- (setq expr-start (match-end 0))
- (aset expr-string (1- expr-start) ?\n))
-
- ((string-match "^//" expr-string expr-start)
- (string-match "$" expr-string expr-start)
- (setq expr-start (match-end 0)))
-
- ((string-match hif-token-regexp expr-string expr-start)
- (let ((token (substring expr-string expr-start (match-end 0))))
- (setq expr-start (match-end 0))
- (aset expr-string (1- expr-start) ?\n)
- ;; (message "token: %s" token) (sit-for 1)
- (push (cond
- ((string-equal token "||") 'or)
- ((string-equal token "&&") 'and)
- ((string-equal token "==") 'equal)
- ((string-equal token "!=") 'hif-notequal)
- ((string-equal token "!") 'not)
- ((string-equal token "defined") 'hif-defined)
- ((string-equal token "(") 'lparen)
- ((string-equal token ")") 'rparen)
- ((string-equal token ">") 'hif-greater)
- ((string-equal token "<") 'hif-less)
- ((string-equal token ">=") 'hif-greater-equal)
- ((string-equal token "<=") 'hif-less-equal)
- ((string-equal token "+") 'hif-plus)
- ((string-equal token "-") 'hif-minus)
- (t (intern token)))
- token-list)))
- (t (error "Bad #if expression: %s" expr-string)))))
+ (save-excursion
+ (goto-char start)
+ (while (progn (forward-comment (point-max)) (< (point) end))
+ ;; (message "expr-start = %d" expr-start) (sit-for 1)
+ (cond
+ ((looking-at "\\\\\n")
+ (forward-char 2))
+
+ ((looking-at hif-token-regexp)
+ (let ((token (buffer-substring (point) (match-end 0))))
+ (goto-char (match-end 0))
+ ;; (message "token: %s" token) (sit-for 1)
+ (push (or (cdr (assoc token hif-token-alist))
+ (if (string-equal token "defined") 'hif-defined)
+ (if (string-match "\\`[0-9]*\\'" token)
+ (string-to-number token))
+ (intern token))
+ token-list)))
+ (t (error "Bad #if expression: %s" (buffer-string)))))))
(nreverse token-list)))
;;;-----------------------------------------------------------------
;;; This parser is limited to the operators &&, ||, !, and "defined".
;;; Added ==, !=, +, and -. Gary Oberbrunner, garyo@avs.com, 8/9/94
+(defsubst hif-nexttoken ()
+ "Pop the next token from token-list into the let variable \"hif-token\"."
+ (setq hif-token (pop hif-token-list)))
+
(defun hif-parse-if-exp (hif-token-list)
"Parse the TOKEN-LIST. Return translated list in prefix form."
(hif-nexttoken)
(if hif-token ; is there still a token?
(error "Error: unexpected token: %s" hif-token))))
-(defun hif-nexttoken ()
- "Pop the next token from token-list into the let variable \"hif-token\"."
- (setq hif-token (car hif-token-list))
- (setq hif-token-list (cdr hif-token-list))
- hif-token)
-
(defun hif-expr ()
"Parse an expression as found in #if.
- expr : term | expr '||' term."
- (let ((result (hif-term)))
+ expr : or-expr | or-expr '?' expr ':' expr."
+ (let ((result (hif-or-expr))
+ middle)
+ (while (eq hif-token 'hif-conditional)
+ (hif-nexttoken)
+ (setq middle (hif-expr))
+ (if (eq hif-token 'hif-colon)
+ (progn
+ (hif-nexttoken)
+ (setq result (list 'hif-conditional result middle (hif-expr))))
+ (error "Error: unexpected token: %s" hif-token)))
+ result))
+
+(defun hif-or-expr ()
+ "Parse n or-expr : and-expr | or-expr '||' and-expr."
+ (let ((result (hif-and-expr)))
(while (eq hif-token 'or)
(hif-nexttoken)
- (setq result (list 'or result (hif-term))))
+ (setq result (list 'hif-or result (hif-and-expr))))
result))
-(defun hif-term ()
- "Parse a term : eq-expr | term '&&' eq-expr."
+(defun hif-and-expr ()
+ "Parse an and-expr : eq-expr | and-expr '&&' eq-expr."
(let ((result (hif-eq-expr)))
(while (eq hif-token 'and)
(hif-nexttoken)
- (setq result (list 'and result (hif-eq-expr))))
+ (setq result (list 'hif-and result (hif-eq-expr))))
result))
(defun hif-eq-expr ()
math : factor | math '+|-' factor."
(let ((result (hif-factor))
(math-op nil))
- (while (or (eq hif-token 'hif-plus) (eq hif-token 'hif-minus))
+ (while (memq hif-token '(hif-plus hif-minus hif-logior hif-logand))
(setq math-op hif-token)
(hif-nexttoken)
(setq result (list math-op result (hif-factor))))
result))
-
+
(defun hif-factor ()
"Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id."
(cond
((eq hif-token 'not)
(hif-nexttoken)
- (list 'not (hif-factor)))
+ (list 'hif-not (hif-factor)))
((eq hif-token 'lparen)
(hif-nexttoken)
((eq hif-token 'hif-defined)
(hif-nexttoken)
- (if (not (eq hif-token 'lparen))
- (error "Error: expected \"(\" after \"defined\""))
- (hif-nexttoken)
- (let ((ident hif-token))
+ (let ((paren (when (eq hif-token 'lparen) (hif-nexttoken) t))
+ (ident hif-token))
(if (memq hif-token '(or and not hif-defined lparen rparen))
(error "Error: unexpected token: %s" hif-token))
- (hif-nexttoken)
- (unless (eq hif-token 'rparen)
- (error "Error: expected \")\" after identifier"))
+ (when paren
+ (hif-nexttoken)
+ (unless (eq hif-token 'rparen)
+ (error "Error: expected \")\" after identifier")))
(hif-nexttoken)
`(hif-defined (quote ,ident))))
+ ((numberp hif-token)
+ (prog1 hif-token (hif-nexttoken)))
+
+ ;; Unary plus/minus.
+ ((memq hif-token '(hif-minus hif-plus))
+ (list (prog1 hif-token (hif-nexttoken)) 0 (hif-factor)))
+
(t ; identifier
(let ((ident hif-token))
(if (memq ident '(or and))
((null val) 0)
(t val)))
-(defun hif-plus (a b)
- "Like ordinary plus but treat t and nil as 1 and 0."
- (+ (hif-mathify a) (hif-mathify b)))
-(defun hif-minus (a b)
- "Like ordinary minus but treat t and nil as 1 and 0."
- (- (hif-mathify a) (hif-mathify b)))
-(defun hif-notequal (a b)
- "Like (not (equal A B)) but as one symbol."
- (not (equal a b)))
-(defun hif-greater (a b)
- "Simple comparison."
- (> (hif-mathify a) (hif-mathify b)))
-(defun hif-less (a b)
- "Simple comparison."
- (< (hif-mathify a) (hif-mathify b)))
-(defun hif-greater-equal (a b)
- "Simple comparison."
- (>= (hif-mathify a) (hif-mathify b)))
-(defun hif-less-equal (a b)
- "Simple comparison."
- (<= (hif-mathify a) (hif-mathify b)))
+(defun hif-conditional (a b c)
+ (if (not (zerop (hif-mathify a))) (hif-mathify b) (hif-mathify c)))
+(defun hif-and (a b)
+ (and (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b)))))
+(defun hif-or (a b)
+ (or (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b)))))
+(defun hif-not (a)
+ (zerop (hif-mathify a)))
+
+(defmacro hif-mathify-binop (fun)
+ `(lambda (a b)
+ ,(format "Like `%s' but treat t and nil as 1 and 0." fun)
+ (,fun (hif-mathify a) (hif-mathify b))))
+
+(defalias 'hif-plus (hif-mathify-binop +))
+(defalias 'hif-minus (hif-mathify-binop -))
+(defalias 'hif-notequal (hif-mathify-binop /=))
+(defalias 'hif-greater (hif-mathify-binop >))
+(defalias 'hif-less (hif-mathify-binop <))
+(defalias 'hif-greater-equal (hif-mathify-binop >=))
+(defalias 'hif-less-equal (hif-mathify-binop <=))
+(defalias 'hif-logior (hif-mathify-binop logior))
+(defalias 'hif-logand (hif-mathify-binop logand))
+
;;;----------- end of parser -----------------------
(save-excursion
(let ((negate (looking-at hif-ifndef-regexp)))
(re-search-forward hif-ifx-regexp)
- (let* ((expr-string
- (buffer-substring (point)
- (progn (skip-chars-forward "^\n\r") (point))))
- (expr (hif-infix-to-prefix (hif-tokenize expr-string))))
+ (let* ((tokens (hif-tokenize (point)
+ (progn (hif-end-of-line) (point))))
+ (expr (hif-parse-if-exp tokens)))
;; (message "hif-canonicalized: %s" expr)
(if negate
- (list 'not expr)
+ (list 'hif-not expr)
expr)))))
;;; Only valid if ELSE-P is true.
;;; END The end of the range. (beginning of line)
-(defun hif-make-range (start end &optional else)
+(defsubst hif-make-range (start end &optional else)
(list start else end))
-(defun hif-range-start (range) (elt range 0))
-(defun hif-range-else (range) (elt range 1))
-(defun hif-range-end (range) (elt range 2))
+(defsubst hif-range-start (range) (elt range 0))
+(defsubst hif-range-else (range) (elt range 1))
+(defsubst hif-range-end (range) (elt range 2))
(setq end (point))) ; (save-excursion (end-of-line) (point))
(hif-make-range start end else))))
-
+
;;; A bit slimy.
-;;; NOTE: If there's an #ifdef at the beginning of the file, we can't
-;;; hide it. There's no previous newline to replace. If we added
-;;; one, we'd throw off all the counts. Feh.
(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 (line-end-position 0) (line-end-position)))))
-
+ (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
;;; There are four cases. The #ifX expression is "taken" if it
;;; the hide-ifdef-evaluator returns T. Presumably, this means the code
;;; inside the #ifdef would be included when the program was
-;;; compiled.
+;;; compiled.
;;;
;;; Case 1: #ifX taken, and there's an #else.
;;; The #else part must be hidden. The #if (then) part must be
(let ((test (hif-canonicalize))
(range (hif-find-range)))
;; (message "test = %s" test) (sit-for 1)
-
+
(hif-hide-line (hif-range-end range))
- (if (funcall hide-ifdef-evaluator test)
- (cond ((hif-range-else range) ; case 1
+ (if (not (hif-not (funcall hide-ifdef-evaluator test)))
+ (cond ((hif-range-else range) ; case 1
(hif-hide-line (hif-range-else range))
- (hide-ifdef-region (hif-range-else range)
+ (hide-ifdef-region (hif-range-else range)
(1- (hif-range-end range)))
(hif-recurse-on (hif-range-start range)
(hif-range-else range)))
;;===%%SF%% exports (Start) ===
-;;;###autoload
-(defcustom hide-ifdef-initially nil
- "*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."
- :type 'boolean
- :group 'hide-ifdef)
-
-;;;###autoload
-(defcustom hide-ifdef-lines nil
- "*Non-nil means hide the #ifX, #else, and #endif lines."
- :type 'boolean
- :group 'hide-ifdef)
-
(defun hide-ifdef-toggle-read-only ()
"Toggle `hide-ifdef-read-only'."
(interactive)
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."
(interactive "SDefine what? ")
(defun hide-ifdefs (&optional nomsg)
- "Hide the contents of some #ifdefs.
-Assume that defined symbols have been added to `hide-ifdef-env'.
+ "Hide the contents of some #ifdefs.
+Assume that defined symbols have been added to `hide-ifdef-env'.
The text hidden is the text that would not be included by the C
preprocessor if it were given the file with those symbols defined.
(setq hide-ifdef-hiding t))
(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)
- (if hide-ifdef-lines
- (save-excursion
- (beginning-of-line)
- (hif-show-ifdef-region (1- (point)) (progn (end-of-line) (point))))
- (let ((top-bottom (hif-find-ifdef-block)))
+ (let ((top-bottom (hif-find-ifdef-block)))
+ (if hide-ifdef-lines
+ (hif-show-ifdef-region
+ (save-excursion
+ (goto-char (car top-bottom)) (line-beginning-position))
+ (save-excursion
+ (goto-char (1+ (cdr top-bottom)))
+ (hif-end-of-line) (point)))
(hif-show-ifdef-region (1- (car top-bottom)) (cdr top-bottom)))))
(defun hide-ifdef-use-define-alist (name)
"Set `hide-ifdef-env' to the define list specified by NAME."
- (interactive "SUse define list: ")
+ (interactive
+ (list (completing-read "Use define list: "
+ (mapcar (lambda (x) (symbol-name (car x)))
+ hide-ifdef-define-alist)
+ nil t)))
+ (if (stringp name) (setq name (intern name)))
(let ((define-list (assoc name hide-ifdef-define-alist)))
(if define-list
(setq hide-ifdef-env
(provide 'hideif)
+;; arch-tag: c6381d17-a59a-483a-b945-658f22277981
;;; hideif.el ends here