diff options
| author | Andreas Schwab | 1998-10-13 09:52:54 +0000 |
|---|---|---|
| committer | Andreas Schwab | 1998-10-13 09:52:54 +0000 |
| commit | 4e391a67d1f2a31a76f670ee373fa8f26bedded1 (patch) | |
| tree | 1f39430a087ce49b1a5f917fa075da1b8f032c20 | |
| parent | 82e6e5afd830ca81edbd4a675da204df88ab7eed (diff) | |
| download | emacs-4e391a67d1f2a31a76f670ee373fa8f26bedded1.tar.gz emacs-4e391a67d1f2a31a76f670ee373fa8f26bedded1.zip | |
(hide-ifdef-env, hif-outside-read-only):
Move declaration before first use.
(hif-parse-if-exp, hif-nexttoken, hif-expr, hif-term, hif-eq-expr,
hif-math, hif-factor): Rename token to hif-token and token-list to
hif-token-list.
(hif-token, hif-token-list): Declare them.
(hif-find-ifdef-block): Return cons of top and bottom point
instead of setting dynamically bound variables.
(hide-ifdef-block, show-ifdef-block): Use return value of
hif-find-ifdef-block.
| -rw-r--r-- | lisp/progmodes/hideif.el | 114 |
1 files changed, 58 insertions, 56 deletions
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el index d746c0ca441..1e3bff46e61 100644 --- a/lisp/progmodes/hideif.el +++ b/lisp/progmodes/hideif.el | |||
| @@ -185,6 +185,12 @@ | |||
| 185 | (modify-syntax-entry ?& "." hide-ifdef-syntax-table) | 185 | (modify-syntax-entry ?& "." hide-ifdef-syntax-table) |
| 186 | (modify-syntax-entry ?\| "." hide-ifdef-syntax-table) | 186 | (modify-syntax-entry ?\| "." hide-ifdef-syntax-table) |
| 187 | 187 | ||
| 188 | (defvar hide-ifdef-env nil | ||
| 189 | "An alist of defined symbols and their values.") | ||
| 190 | |||
| 191 | (defvar hif-outside-read-only nil | ||
| 192 | "Internal variable. Saves the value of `buffer-read-only' while hiding.") | ||
| 193 | |||
| 188 | ;;;###autoload | 194 | ;;;###autoload |
| 189 | (defun hide-ifdef-mode (arg) | 195 | (defun hide-ifdef-mode (arg) |
| 190 | "Toggle Hide-Ifdef mode. This is a minor mode, albeit a large one. | 196 | "Toggle Hide-Ifdef mode. This is a minor mode, albeit a large one. |
| @@ -304,9 +310,6 @@ that form should be displayed.") | |||
| 304 | (defvar hif-undefined-symbol nil | 310 | (defvar hif-undefined-symbol nil |
| 305 | "...is by default considered to be false.") | 311 | "...is by default considered to be false.") |
| 306 | 312 | ||
| 307 | (defvar hide-ifdef-env nil | ||
| 308 | "An alist of defined symbols and their values.") | ||
| 309 | |||
| 310 | 313 | ||
| 311 | (defun hif-set-var (var value) | 314 | (defun hif-set-var (var value) |
| 312 | "Prepend (var value) pair to hide-ifdef-env." | 315 | "Prepend (var value) pair to hide-ifdef-env." |
| @@ -344,6 +347,10 @@ that form should be displayed.") | |||
| 344 | (defconst hif-ifx-else-endif-regexp | 347 | (defconst hif-ifx-else-endif-regexp |
| 345 | (concat hif-ifx-regexp "\\|" hif-else-regexp "\\|" hif-endif-regexp)) | 348 | (concat hif-ifx-regexp "\\|" hif-else-regexp "\\|" hif-endif-regexp)) |
| 346 | 349 | ||
| 350 | ; Used to store the current token and the whole token list during parsing. | ||
| 351 | ; Only bound dynamically. | ||
| 352 | (defvar hif-token) | ||
| 353 | (defvar hif-token-list) | ||
| 347 | 354 | ||
| 348 | (defun hif-infix-to-prefix (token-list) | 355 | (defun hif-infix-to-prefix (token-list) |
| 349 | "Convert list of tokens in infix into prefix list" | 356 | "Convert list of tokens in infix into prefix list" |
| @@ -424,25 +431,25 @@ that form should be displayed.") | |||
| 424 | ;;; This parser is limited to the operators &&, ||, !, and "defined". | 431 | ;;; This parser is limited to the operators &&, ||, !, and "defined". |
| 425 | ;;; Added ==, !=, +, and -. Gary Oberbrunner, garyo@avs.com, 8/9/94 | 432 | ;;; Added ==, !=, +, and -. Gary Oberbrunner, garyo@avs.com, 8/9/94 |
| 426 | 433 | ||
| 427 | (defun hif-parse-if-exp (token-list) | 434 | (defun hif-parse-if-exp (hif-token-list) |
| 428 | "Parse the TOKEN-LIST. Return translated list in prefix form." | 435 | "Parse the TOKEN-LIST. Return translated list in prefix form." |
| 429 | (hif-nexttoken) | 436 | (hif-nexttoken) |
| 430 | (prog1 | 437 | (prog1 |
| 431 | (hif-expr) | 438 | (hif-expr) |
| 432 | (if token ; is there still a token? | 439 | (if hif-token ; is there still a token? |
| 433 | (error "Error: unexpected token: %s" token)))) | 440 | (error "Error: unexpected token: %s" hif-token)))) |
| 434 | 441 | ||
| 435 | (defun hif-nexttoken () | 442 | (defun hif-nexttoken () |
| 436 | "Pop the next token from token-list into the let variable \"token\"." | 443 | "Pop the next token from token-list into the let variable \"hif-token\"." |
| 437 | (setq token (car token-list)) | 444 | (setq hif-token (car hif-token-list)) |
| 438 | (setq token-list (cdr token-list)) | 445 | (setq hif-token-list (cdr hif-token-list)) |
| 439 | token) | 446 | hif-token) |
| 440 | 447 | ||
| 441 | (defun hif-expr () | 448 | (defun hif-expr () |
| 442 | "Parse an expression as found in #if. | 449 | "Parse an expression as found in #if. |
| 443 | expr : term | expr '||' term." | 450 | expr : term | expr '||' term." |
| 444 | (let ((result (hif-term))) | 451 | (let ((result (hif-term))) |
| 445 | (while (eq token 'or) | 452 | (while (eq hif-token 'or) |
| 446 | (hif-nexttoken) | 453 | (hif-nexttoken) |
| 447 | (setq result (list 'or result (hif-term)))) | 454 | (setq result (list 'or result (hif-term)))) |
| 448 | result)) | 455 | result)) |
| @@ -450,7 +457,7 @@ that form should be displayed.") | |||
| 450 | (defun hif-term () | 457 | (defun hif-term () |
| 451 | "Parse a term : eq-expr | term '&&' eq-expr." | 458 | "Parse a term : eq-expr | term '&&' eq-expr." |
| 452 | (let ((result (hif-eq-expr))) | 459 | (let ((result (hif-eq-expr))) |
| 453 | (while (eq token 'and) | 460 | (while (eq hif-token 'and) |
| 454 | (hif-nexttoken) | 461 | (hif-nexttoken) |
| 455 | (setq result (list 'and result (hif-eq-expr)))) | 462 | (setq result (list 'and result (hif-eq-expr)))) |
| 456 | result)) | 463 | result)) |
| @@ -459,9 +466,9 @@ that form should be displayed.") | |||
| 459 | "Parse an eq-expr : math | eq-expr `=='|`!='|`<'|`>'|`>='|`<=' math." | 466 | "Parse an eq-expr : math | eq-expr `=='|`!='|`<'|`>'|`>='|`<=' math." |
| 460 | (let ((result (hif-math)) | 467 | (let ((result (hif-math)) |
| 461 | (eq-token nil)) | 468 | (eq-token nil)) |
| 462 | (while (memq token '(equal hif-notequal hif-greater hif-less | 469 | (while (memq hif-token '(equal hif-notequal hif-greater hif-less |
| 463 | hif-greater-equal hif-less-equal)) | 470 | hif-greater-equal hif-less-equal)) |
| 464 | (setq eq-token token) | 471 | (setq eq-token hif-token) |
| 465 | (hif-nexttoken) | 472 | (hif-nexttoken) |
| 466 | (setq result (list eq-token result (hif-math)))) | 473 | (setq result (list eq-token result (hif-math)))) |
| 467 | result)) | 474 | result)) |
| @@ -471,8 +478,8 @@ that form should be displayed.") | |||
| 471 | math : factor | math '+|-' factor." | 478 | math : factor | math '+|-' factor." |
| 472 | (let ((result (hif-factor)) | 479 | (let ((result (hif-factor)) |
| 473 | (math-op nil)) | 480 | (math-op nil)) |
| 474 | (while (or (eq token 'hif-plus) (eq token 'hif-minus)) | 481 | (while (or (eq hif-token 'hif-plus) (eq hif-token 'hif-minus)) |
| 475 | (setq math-op token) | 482 | (setq math-op hif-token) |
| 476 | (hif-nexttoken) | 483 | (hif-nexttoken) |
| 477 | (setq result (list math-op result (hif-factor)))) | 484 | (setq result (list math-op result (hif-factor)))) |
| 478 | result)) | 485 | result)) |
| @@ -480,35 +487,35 @@ that form should be displayed.") | |||
| 480 | (defun hif-factor () | 487 | (defun hif-factor () |
| 481 | "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." | 488 | "Parse a factor: '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
| 482 | (cond | 489 | (cond |
| 483 | ((eq token 'not) | 490 | ((eq hif-token 'not) |
| 484 | (hif-nexttoken) | 491 | (hif-nexttoken) |
| 485 | (list 'not (hif-factor))) | 492 | (list 'not (hif-factor))) |
| 486 | 493 | ||
| 487 | ((eq token 'lparen) | 494 | ((eq hif-token 'lparen) |
| 488 | (hif-nexttoken) | 495 | (hif-nexttoken) |
| 489 | (let ((result (hif-expr))) | 496 | (let ((result (hif-expr))) |
| 490 | (if (not (eq token 'rparen)) | 497 | (if (not (eq hif-token 'rparen)) |
| 491 | (error "Bad token in parenthesized expression: %s" token) | 498 | (error "Bad token in parenthesized expression: %s" hif-token) |
| 492 | (hif-nexttoken) | 499 | (hif-nexttoken) |
| 493 | result))) | 500 | result))) |
| 494 | 501 | ||
| 495 | ((eq token 'hif-defined) | 502 | ((eq hif-token 'hif-defined) |
| 496 | (hif-nexttoken) | 503 | (hif-nexttoken) |
| 497 | (if (not (eq token 'lparen)) | 504 | (if (not (eq hif-token 'lparen)) |
| 498 | (error "Error: expected \"(\" after \"defined\"")) | 505 | (error "Error: expected \"(\" after \"defined\"")) |
| 499 | (hif-nexttoken) | 506 | (hif-nexttoken) |
| 500 | (let ((ident token)) | 507 | (let ((ident hif-token)) |
| 501 | (if (memq token '(or and not hif-defined lparen rparen)) | 508 | (if (memq hif-token '(or and not hif-defined lparen rparen)) |
| 502 | (error "Error: unexpected token: %s" token)) | 509 | (error "Error: unexpected token: %s" hif-token)) |
| 503 | (hif-nexttoken) | 510 | (hif-nexttoken) |
| 504 | (if (not (eq token 'rparen)) | 511 | (if (not (eq hif-token 'rparen)) |
| 505 | (error "Error: expected \")\" after identifier")) | 512 | (error "Error: expected \")\" after identifier")) |
| 506 | (hif-nexttoken) | 513 | (hif-nexttoken) |
| 507 | (` (hif-defined (quote (, ident)))) | 514 | (` (hif-defined (quote (, ident)))) |
| 508 | )) | 515 | )) |
| 509 | 516 | ||
| 510 | (t ; identifier | 517 | (t ; identifier |
| 511 | (let ((ident token)) | 518 | (let ((ident hif-token)) |
| 512 | (if (memq ident '(or and)) | 519 | (if (memq ident '(or and)) |
| 513 | (error "Error: missing identifier")) | 520 | (error "Error: missing identifier")) |
| 514 | (hif-nexttoken) | 521 | (hif-nexttoken) |
| @@ -901,9 +908,6 @@ It does not do the work that's pointless to redo on a recursive entry." | |||
| 901 | :type 'boolean | 908 | :type 'boolean |
| 902 | :group 'hide-ifdef) | 909 | :group 'hide-ifdef) |
| 903 | 910 | ||
| 904 | (defvar hif-outside-read-only nil | ||
| 905 | "Internal variable. Saves the value of `buffer-read-only' while hiding.") | ||
| 906 | |||
| 907 | ;;;###autoload | 911 | ;;;###autoload |
| 908 | (defcustom hide-ifdef-lines nil | 912 | (defcustom hide-ifdef-lines nil |
| 909 | "*Non-nil means hide the #ifX, #else, and #endif lines." | 913 | "*Non-nil means hide the #ifX, #else, and #endif lines." |
| @@ -982,24 +986,23 @@ Turn off hiding by calling `show-ifdefs'." | |||
| 982 | 986 | ||
| 983 | (defun hif-find-ifdef-block () | 987 | (defun hif-find-ifdef-block () |
| 984 | "Utility for hide and show `ifdef-block'. | 988 | "Utility for hide and show `ifdef-block'. |
| 985 | Set top and bottom of ifdef block." | 989 | Return as (TOP . BOTTOM) the extent of ifdef block." |
| 986 | (let (max-bottom) | 990 | (let (max-bottom) |
| 987 | (save-excursion | 991 | (cons (save-excursion |
| 988 | (beginning-of-line) | 992 | (beginning-of-line) |
| 989 | (if (not (or (hif-looking-at-else) (hif-looking-at-ifX))) | 993 | (if (not (or (hif-looking-at-else) (hif-looking-at-ifX))) |
| 990 | (up-ifdef)) | 994 | (up-ifdef)) |
| 991 | (setq top (point)) | 995 | (prog1 (point) |
| 992 | (hif-ifdef-to-endif) | 996 | (hif-ifdef-to-endif) |
| 993 | (setq max-bottom (1- (point)))) | 997 | (setq max-bottom (1- (point))))) |
| 994 | (save-excursion | 998 | (save-excursion |
| 995 | (beginning-of-line) | 999 | (beginning-of-line) |
| 996 | (if (not (hif-looking-at-endif)) | 1000 | (if (not (hif-looking-at-endif)) |
| 997 | (hif-find-next-relevant)) | 1001 | (hif-find-next-relevant)) |
| 998 | (while (hif-looking-at-ifX) | 1002 | (while (hif-looking-at-ifX) |
| 999 | (hif-ifdef-to-endif) | 1003 | (hif-ifdef-to-endif) |
| 1000 | (hif-find-next-relevant)) | 1004 | (hif-find-next-relevant)) |
| 1001 | (setq bottom (min max-bottom (1- (point)))))) | 1005 | (min max-bottom (1- (point))))))) |
| 1002 | ) | ||
| 1003 | 1006 | ||
| 1004 | 1007 | ||
| 1005 | (defun hide-ifdef-block () | 1008 | (defun hide-ifdef-block () |
| @@ -1008,13 +1011,13 @@ Set top and bottom of ifdef block." | |||
| 1008 | (if (not hide-ifdef-mode) | 1011 | (if (not hide-ifdef-mode) |
| 1009 | (hide-ifdef-mode 1)) | 1012 | (hide-ifdef-mode 1)) |
| 1010 | (setq selective-display t) | 1013 | (setq selective-display t) |
| 1011 | (let (top bottom (inhibit-read-only t)) | 1014 | (let ((top-bottom (hif-find-ifdef-block)) |
| 1012 | (hif-find-ifdef-block) ; set top and bottom - dynamic scoping | 1015 | (inhibit-read-only t)) |
| 1013 | (hide-ifdef-region top bottom) | 1016 | (hide-ifdef-region (car top-bottom) (cdr top-bottom)) |
| 1014 | (if hide-ifdef-lines | 1017 | (if hide-ifdef-lines |
| 1015 | (progn | 1018 | (progn |
| 1016 | (hif-hide-line top) | 1019 | (hif-hide-line (car top-bottom)) |
| 1017 | (hif-hide-line (1+ bottom)))) | 1020 | (hif-hide-line (1+ (cdr top-bottom))))) |
| 1018 | (setq hide-ifdef-hiding t)) | 1021 | (setq hide-ifdef-hiding t)) |
| 1019 | (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) | 1022 | (setq buffer-read-only (or hide-ifdef-read-only hif-outside-read-only))) |
| 1020 | 1023 | ||
| @@ -1028,9 +1031,8 @@ Set top and bottom of ifdef block." | |||
| 1028 | (beginning-of-line) | 1031 | (beginning-of-line) |
| 1029 | (hif-show-ifdef-region (1- (point)) (progn (end-of-line) (point)))) | 1032 | (hif-show-ifdef-region (1- (point)) (progn (end-of-line) (point)))) |
| 1030 | 1033 | ||
| 1031 | (let (top bottom) | 1034 | (let ((top-bottom (hif-find-ifdef-block))) |
| 1032 | (hif-find-ifdef-block) | 1035 | (hif-show-ifdef-region (1- (car top-bottom)) (cdr top-bottom)))))) |
| 1033 | (hif-show-ifdef-region (1- top) bottom))))) | ||
| 1034 | 1036 | ||
| 1035 | 1037 | ||
| 1036 | ;;; definition alist support | 1038 | ;;; definition alist support |