diff options
| author | Alan Mackenzie | 2020-12-28 20:42:25 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2020-12-28 20:42:25 +0000 |
| commit | d180a41dbb8e4e8d94d30a023c2d86d92c73c4f1 (patch) | |
| tree | 5b811a6f87e0aac22483430215942a6add985852 | |
| parent | c7fdf8688388f137dbfab2f372fa33c24241b83a (diff) | |
| download | emacs-d180a41dbb8e4e8d94d30a023c2d86d92c73c4f1.tar.gz emacs-d180a41dbb8e4e8d94d30a023c2d86d92c73c4f1.zip | |
CC Mode: Add newish AWK Mode facilities, as used in gawk-4.
* lisp/progmodes/cc-awk.el (c-awk-font-lock-invalid-namespace-separators):
New function.
(c-awk-context-expand-fl-region): New function.
(awk-font-lock-keywords): Enhance handling of function declarations to include
:: tokens. Fontify new system variable names FPAT, FUNCTAB, PREC, ROUNDMODE,
SYNTAB. Fontify new keywords BEGINFILE and ENDFILE. Fontify new system
functions asorti, dcngettext, isarray, patsplit, typeof. Fontify the new
directives @include, @load, @namespace. Call
c-awk-font-lock-invalid-namespace-separators as a matcher.
* lisp/progmodes/cc-fonts.el (top level): No longer require 'cc-awk.
* lisp/progmodes/cc-langs.el (c-before-context-fontification-functions): Give
AWK the value c-awk-context-expand-fl-region rather than nil.
* lisp/progmodes/cc-mode.el (top level): Declare awk-mode-syntax-table as a
variable.
| -rw-r--r-- | lisp/progmodes/cc-awk.el | 101 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 3 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 1 |
4 files changed, 89 insertions, 18 deletions
diff --git a/lisp/progmodes/cc-awk.el b/lisp/progmodes/cc-awk.el index 52e6da6f4ac..841c3a4bb6d 100644 --- a/lisp/progmodes/cc-awk.el +++ b/lisp/progmodes/cc-awk.el | |||
| @@ -49,9 +49,11 @@ | |||
| 49 | (load "cc-bytecomp" nil t))) | 49 | (load "cc-bytecomp" nil t))) |
| 50 | 50 | ||
| 51 | (cc-require 'cc-defs) | 51 | (cc-require 'cc-defs) |
| 52 | (cc-require-when-compile 'cc-langs) | ||
| 53 | (cc-require-when-compile 'cc-fonts) | ||
| 54 | (cc-require 'cc-engine) | ||
| 52 | 55 | ||
| 53 | ;; Silence the byte compiler. | 56 | ;; Silence the byte compiler. |
| 54 | (cc-bytecomp-defvar font-lock-mode) ; Checked with boundp before use. | ||
| 55 | (cc-bytecomp-defvar c-new-BEG) | 57 | (cc-bytecomp-defvar c-new-BEG) |
| 56 | (cc-bytecomp-defvar c-new-END) | 58 | (cc-bytecomp-defvar c-new-END) |
| 57 | 59 | ||
| @@ -649,6 +651,46 @@ | |||
| 649 | ;; several lines back. The elisp "advice" feature is used on these functions | 651 | ;; several lines back. The elisp "advice" feature is used on these functions |
| 650 | ;; to allow this. | 652 | ;; to allow this. |
| 651 | 653 | ||
| 654 | (defun c-awk-font-lock-invalid-namespace-separators (limit) | ||
| 655 | ;; This function will be called from font-lock for a region bounded by POINT | ||
| 656 | ;; and LIMIT, as though it were to identify a keyword for | ||
| 657 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and | ||
| 658 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based | ||
| 659 | ;; Fontification". | ||
| 660 | ;; | ||
| 661 | ;; This function gives invalid GAWK namepace separators (::) | ||
| 662 | ;; font-lock-warning-face. "Invalid" here means there are spaces, etc., | ||
| 663 | ;; around a separator, or there are more than one of them in an identifier. | ||
| 664 | ;; Invalid separators inside function declaration parentheses are handled | ||
| 665 | ;; elsewhere. | ||
| 666 | (while (and | ||
| 667 | (< (point) limit) | ||
| 668 | (c-syntactic-re-search-forward | ||
| 669 | (eval-when-compile | ||
| 670 | (concat "\\([^" (c-lang-const c-symbol-chars awk) "]::\\)" | ||
| 671 | "\\|" | ||
| 672 | ;; "\\(::[^" (c-lang-const c-symbol-start awk) "]\\)" | ||
| 673 | "\\(::[^" c-alpha "_" "]\\)" | ||
| 674 | "\\|" | ||
| 675 | "\\(::[" (c-lang-const c-symbol-chars awk) "]*::\\)")) | ||
| 676 | limit 'bound)) | ||
| 677 | (cond | ||
| 678 | ((match-beginning 1) ; " ::" | ||
| 679 | (c-put-font-lock-face (1+ (match-beginning 1)) (match-end 1) | ||
| 680 | 'font-lock-warning-face) | ||
| 681 | (goto-char (- (match-end 1) 2))) | ||
| 682 | ((match-beginning 2) ; ":: " | ||
| 683 | (c-put-font-lock-face (match-beginning 2) (1- (match-end 2)) | ||
| 684 | 'font-lock-warning-face) | ||
| 685 | (goto-char (1- (match-end 2)))) | ||
| 686 | (t ; "::foo::" | ||
| 687 | (c-put-font-lock-face (match-beginning 3) (+ 2 (match-beginning 3)) | ||
| 688 | 'font-lock-warning-face) | ||
| 689 | (c-put-font-lock-face (- (match-end 3) 2) (match-end 3) | ||
| 690 | 'font-lock-warning-face) | ||
| 691 | (goto-char (- (match-end 3) 2))))) | ||
| 692 | nil) | ||
| 693 | |||
| 652 | (defun c-awk-beginning-of-logical-line (&optional pos) | 694 | (defun c-awk-beginning-of-logical-line (&optional pos) |
| 653 | ;; Go back to the start of the (apparent) current line (or the start of the | 695 | ;; Go back to the start of the (apparent) current line (or the start of the |
| 654 | ;; line containing POS), returning the buffer position of that point. I.e., | 696 | ;; line containing POS), returning the buffer position of that point. I.e., |
| @@ -900,6 +942,13 @@ | |||
| 900 | (goto-char c-new-BEG) | 942 | (goto-char c-new-BEG) |
| 901 | (c-awk-set-syntax-table-properties c-new-END))) | 943 | (c-awk-set-syntax-table-properties c-new-END))) |
| 902 | 944 | ||
| 945 | (defun c-awk-context-expand-fl-region (beg end) | ||
| 946 | ;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of the | ||
| 947 | ;; logical line BEG is on, and NEW-END is the beginning of the line after | ||
| 948 | ;; the end of the logical line that END is on. | ||
| 949 | (cons (save-excursion (c-awk-beginning-of-logical-line beg)) | ||
| 950 | (c-awk-beyond-logical-line end))) | ||
| 951 | |||
| 903 | ;; Awk regexps written with help from Peter Galbraith | 952 | ;; Awk regexps written with help from Peter Galbraith |
| 904 | ;; <galbraith@mixing.qc.dfo.ca>. | 953 | ;; <galbraith@mixing.qc.dfo.ca>. |
| 905 | ;; Take GNU Emacs's 'words out of the following regexp-opts. They don't work | 954 | ;; Take GNU Emacs's 'words out of the following regexp-opts. They don't work |
| @@ -907,18 +956,34 @@ | |||
| 907 | (defconst awk-font-lock-keywords | 956 | (defconst awk-font-lock-keywords |
| 908 | (eval-when-compile | 957 | (eval-when-compile |
| 909 | (list | 958 | (list |
| 910 | ;; Function names. | 959 | ;; Function declarations. |
| 911 | '("^\\s *\\(func\\(tion\\)?\\)\\>\\s *\\(\\sw+\\)?" | 960 | `(,(c-make-font-lock-search-function |
| 912 | (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t)) | 961 | "^\\s *\\(func\\(tion\\)?\\)\\s +\\(\\(\\sw+\\(::\\sw+\\)?\\)\\s *\\)?\\(([^()]*)\\)?" |
| 913 | ;; | 962 | '(1 font-lock-keyword-face t) |
| 963 | ;; We can't use LAXMATCH in `c-make-font-lock-search-function', so.... | ||
| 964 | '((when (match-beginning 4) | ||
| 965 | (c-put-font-lock-face | ||
| 966 | (match-beginning 4) (match-end 4) font-lock-function-name-face) | ||
| 967 | nil)) | ||
| 968 | ;; Put warning face on any use of :: inside the parens. | ||
| 969 | '((when (match-beginning 6) | ||
| 970 | (goto-char (1+ (match-beginning 6))) | ||
| 971 | (let ((end (1- (match-end 6)))) | ||
| 972 | (while (and (< (point) end) | ||
| 973 | (c-syntactic-re-search-forward "::" end t)) | ||
| 974 | (c-put-font-lock-face (- (point) 2) (point) | ||
| 975 | 'font-lock-warning-face))) | ||
| 976 | nil)))) | ||
| 977 | |||
| 914 | ;; Variable names. | 978 | ;; Variable names. |
| 915 | (cons | 979 | (cons |
| 916 | (concat "\\<" | 980 | (concat "\\<" |
| 917 | (regexp-opt | 981 | (regexp-opt |
| 918 | '("ARGC" "ARGIND" "ARGV" "BINMODE" "CONVFMT" "ENVIRON" | 982 | '("ARGC" "ARGIND" "ARGV" "BINMODE" "CONVFMT" "ENVIRON" |
| 919 | "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" | 983 | "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" "FPAT" "FS" "FUNCTAB" |
| 920 | "LINT" "NF" "NR" "OFMT" "OFS" "ORS" "PROCINFO" "RLENGTH" | 984 | "IGNORECASE" "LINT" "NF" "NR" "OFMT" "OFS" "ORS" "PREC" |
| 921 | "RS" "RSTART" "RT" "SUBSEP" "TEXTDOMAIN") t) "\\>") | 985 | "PROCINFO" "RLENGTH" "ROUNDMODE" "RS" "RSTART" "RT" "SUBSEP" |
| 986 | "SYNTAB" "TEXTDOMAIN") t) "\\>") | ||
| 922 | 'font-lock-variable-name-face) | 987 | 'font-lock-variable-name-face) |
| 923 | 988 | ||
| 924 | ;; Special file names. (acm, 2002/7/22) | 989 | ;; Special file names. (acm, 2002/7/22) |
| @@ -949,7 +1014,8 @@ std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\ | |||
| 949 | ;; Keywords. | 1014 | ;; Keywords. |
| 950 | (concat "\\<" | 1015 | (concat "\\<" |
| 951 | (regexp-opt | 1016 | (regexp-opt |
| 952 | '("BEGIN" "END" "break" "case" "continue" "default" "delete" | 1017 | '("BEGIN" "BEGINFILE" "END" "ENDFILE" |
| 1018 | "break" "case" "continue" "default" "delete" | ||
| 953 | "do" "else" "exit" "for" "getline" "if" "in" "next" | 1019 | "do" "else" "exit" "for" "getline" "if" "in" "next" |
| 954 | "nextfile" "return" "switch" "while") | 1020 | "nextfile" "return" "switch" "while") |
| 955 | t) "\\>") | 1021 | t) "\\>") |
| @@ -959,16 +1025,20 @@ std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\ | |||
| 959 | ,(concat | 1025 | ,(concat |
| 960 | "\\<" | 1026 | "\\<" |
| 961 | (regexp-opt | 1027 | (regexp-opt |
| 962 | '("adump" "and" "asort" "atan2" "bindtextdomain" "close" | 1028 | '("adump" "and" "asort" "asorti" "atan2" "bindtextdomain" "close" |
| 963 | "compl" "cos" "dcgettext" "exp" "extension" "fflush" | 1029 | "compl" "cos" "dcgettext" "dcngettext" "exp" "extension" "fflush" |
| 964 | "gensub" "gsub" "index" "int" "length" "log" "lshift" | 1030 | "gensub" "gsub" "index" "int" "isarray" "length" "log" "lshift" |
| 965 | "match" "mktime" "or" "print" "printf" "rand" "rshift" | 1031 | "match" "mktime" "or" "patsplit" "print" "printf" "rand" "rshift" |
| 966 | "sin" "split" "sprintf" "sqrt" "srand" "stopme" | 1032 | "sin" "split" "sprintf" "sqrt" "srand" "stopme" |
| 967 | "strftime" "strtonum" "sub" "substr" "system" | 1033 | "strftime" "strtonum" "sub" "substr" "system" |
| 968 | "systime" "tolower" "toupper" "xor") t) | 1034 | "systime" "tolower" "toupper" "typeof" "xor") |
| 1035 | t) | ||
| 969 | "\\>") | 1036 | "\\>") |
| 970 | 0 c-preprocessor-face-name)) | 1037 | 0 c-preprocessor-face-name)) |
| 971 | 1038 | ||
| 1039 | ;; Directives | ||
| 1040 | '("@\\(include\\|load\\|namespace\\)\\>" 0 c-preprocessor-face-name) | ||
| 1041 | |||
| 972 | ;; gawk debugging keywords. (acm, 2002/7/21) | 1042 | ;; gawk debugging keywords. (acm, 2002/7/21) |
| 973 | ;; (Removed, 2003/6/6. These functions are now fontified as built-ins) | 1043 | ;; (Removed, 2003/6/6. These functions are now fontified as built-ins) |
| 974 | ;; (list (concat "\\<" (regexp-opt '("adump" "stopme") t) "\\>") | 1044 | ;; (list (concat "\\<" (regexp-opt '("adump" "stopme") t) "\\>") |
| @@ -980,6 +1050,9 @@ std\\(err\\|in\\|out\\)\\|user\\)\\)\\>\ | |||
| 980 | c-awk-escaped-nls*-with-space* "(") | 1050 | c-awk-escaped-nls*-with-space* "(") |
| 981 | (0 'font-lock-warning-face)) | 1051 | (0 'font-lock-warning-face)) |
| 982 | 1052 | ||
| 1053 | ;; Double :: tokens, or the same with space(s) around them. | ||
| 1054 | #'c-awk-font-lock-invalid-namespace-separators | ||
| 1055 | |||
| 983 | ;; Space after \ in what looks like an escaped newline. 2002/5/31 | 1056 | ;; Space after \ in what looks like an escaped newline. 2002/5/31 |
| 984 | '("\\\\\\s +$" 0 font-lock-warning-face t) | 1057 | '("\\\\\\s +$" 0 font-lock-warning-face t) |
| 985 | 1058 | ||
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index e403c49e398..94e087f38e0 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -76,9 +76,6 @@ | |||
| 76 | (cc-require-when-compile 'cc-langs) | 76 | (cc-require-when-compile 'cc-langs) |
| 77 | (cc-require 'cc-vars) | 77 | (cc-require 'cc-vars) |
| 78 | (cc-require 'cc-engine) | 78 | (cc-require 'cc-engine) |
| 79 | (cc-require-when-compile 'cc-awk) ; Change from cc-require, 2003/6/18 to | ||
| 80 | ;; prevent cc-awk being loaded when it's not needed. There is now a (require | ||
| 81 | ;; 'cc-awk) in (defun awk-mode ..). | ||
| 82 | 79 | ||
| 83 | ;; Avoid repeated loading through the eval-after-load directive in | 80 | ;; Avoid repeated loading through the eval-after-load directive in |
| 84 | ;; cc-mode.el. | 81 | ;; cc-mode.el. |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 4d1aeaa5cb9..9b13cedc988 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -549,7 +549,7 @@ parameters (point-min), (point-max) and <buffer size>.") | |||
| 549 | 549 | ||
| 550 | (c-lang-defconst c-before-context-fontification-functions | 550 | (c-lang-defconst c-before-context-fontification-functions |
| 551 | t 'c-context-expand-fl-region | 551 | t 'c-context-expand-fl-region |
| 552 | awk nil) | 552 | awk 'c-awk-context-expand-fl-region) |
| 553 | ;; For documentation see the following c-lang-defvar of the same name. | 553 | ;; For documentation see the following c-lang-defvar of the same name. |
| 554 | ;; The value here may be a list of functions or a single function. | 554 | ;; The value here may be a list of functions or a single function. |
| 555 | (c-lang-defvar c-before-context-fontification-functions | 555 | (c-lang-defvar c-before-context-fontification-functions |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index f6d36f5670c..2f1885e5b61 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -113,6 +113,7 @@ | |||
| 113 | ;; Silence the compiler. | 113 | ;; Silence the compiler. |
| 114 | (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs | 114 | (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs |
| 115 | (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1 | 115 | (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1 |
| 116 | (cc-bytecomp-defvar awk-mode-syntax-table) | ||
| 116 | 117 | ||
| 117 | ;; We set this variable during mode init, yet we don't require | 118 | ;; We set this variable during mode init, yet we don't require |
| 118 | ;; font-lock. | 119 | ;; font-lock. |