aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorPaul Eggert2012-05-25 11:19:24 -0700
committerPaul Eggert2012-05-25 11:19:24 -0700
commit42b2a986d9d4b7040fb20c90ec0efeffb78e761a (patch)
treed38e7bf5307837f2f38982757f088100de18a64e /lisp/progmodes
parente4d81efc58695c19154d5f6733d91172b4c3e5b7 (diff)
parenta8d3cbf75d219d7a249fc0623219511179e959da (diff)
downloademacs-42b2a986d9d4b7040fb20c90ec0efeffb78e761a.tar.gz
emacs-42b2a986d9d4b7040fb20c90ec0efeffb78e761a.zip
Merge from trunk.
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-defs.el2
-rw-r--r--lisp/progmodes/cc-engine.el44
-rw-r--r--lisp/progmodes/compile.el30
-rw-r--r--lisp/progmodes/ebnf2ps.el4
-rw-r--r--lisp/progmodes/etags.el60
-rw-r--r--lisp/progmodes/f90.el19
-rw-r--r--lisp/progmodes/flymake.el2
-rw-r--r--lisp/progmodes/gdb-mi.el211
-rw-r--r--lisp/progmodes/gud.el5
-rw-r--r--lisp/progmodes/idlw-shell.el23
-rw-r--r--lisp/progmodes/idlwave.el9
-rw-r--r--lisp/progmodes/js.el21
-rw-r--r--lisp/progmodes/make-mode.el1
-rw-r--r--lisp/progmodes/meta-mode.el2
-rw-r--r--lisp/progmodes/octave-mod.el19
-rw-r--r--lisp/progmodes/pascal.el55
-rw-r--r--lisp/progmodes/prolog.el435
-rw-r--r--lisp/progmodes/python.el39
-rw-r--r--lisp/progmodes/ruby-mode.el89
-rw-r--r--lisp/progmodes/sh-script.el548
-rw-r--r--lisp/progmodes/verilog-mode.el1176
-rw-r--r--lisp/progmodes/which-func.el9
22 files changed, 1836 insertions, 967 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 93a72796561..5d758b53b56 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -93,7 +93,7 @@
93 93
94;;; Variables also used at compile time. 94;;; Variables also used at compile time.
95 95
96(defconst c-version "5.32.2" 96(defconst c-version "5.32.3"
97 "CC Mode version number.") 97 "CC Mode version number.")
98 98
99(defconst c-version-sym (intern c-version)) 99(defconst c-version-sym (intern c-version))
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 65e28c11e21..82aee7bdbb9 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2612,13 +2612,24 @@ comment at the start of cc-engine.el for more info."
2612 (setq c-state-point-min (point-min))) 2612 (setq c-state-point-min (point-min)))
2613 2613
2614(defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim) 2614(defun c-append-lower-brace-pair-to-state-cache (from &optional upper-lim)
2615 ;; If there is a brace pair preceding FROM in the buffer (not necessarily 2615 ;; If there is a brace pair preceding FROM in the buffer, at the same level
2616 ;; immediately preceding), push a cons onto `c-state-cache' to represent it. 2616 ;; of nesting (not necessarily immediately preceding), push a cons onto
2617 ;; FROM must not be inside a literal. If UPPER-LIM is non-nil, we append 2617 ;; `c-state-cache' to represent it. FROM must not be inside a literal. If
2618 ;; the highest brace pair whose "}" is below UPPER-LIM. 2618 ;; UPPER-LIM is non-nil, we append the highest brace pair whose "}" is below
2619 ;; UPPER-LIM.
2619 ;; 2620 ;;
2620 ;; Return non-nil when this has been done. 2621 ;; Return non-nil when this has been done.
2621 ;; 2622 ;;
2623 ;; The situation it copes with is this transformation:
2624 ;;
2625 ;; OLD: { (.) {...........}
2626 ;; ^ ^
2627 ;; FROM HERE
2628 ;;
2629 ;; NEW: { {....} (.) {.........
2630 ;; ^ ^ ^
2631 ;; LOWER BRACE PAIR HERE or HERE
2632 ;;
2622 ;; This routine should be fast. Since it can get called a LOT, we maintain 2633 ;; This routine should be fast. Since it can get called a LOT, we maintain
2623 ;; `c-state-brace-pair-desert', a small cache of "failures", such that we 2634 ;; `c-state-brace-pair-desert', a small cache of "failures", such that we
2624 ;; reduce the time wasted in repeated fruitless searches in brace deserts. 2635 ;; reduce the time wasted in repeated fruitless searches in brace deserts.
@@ -2637,10 +2648,25 @@ comment at the start of cc-engine.el for more info."
2637 (unless (and c-state-brace-pair-desert 2648 (unless (and c-state-brace-pair-desert
2638 (eq cache-pos (car c-state-brace-pair-desert)) 2649 (eq cache-pos (car c-state-brace-pair-desert))
2639 (<= from (cdr c-state-brace-pair-desert))) 2650 (<= from (cdr c-state-brace-pair-desert)))
2640 ;; Only search what we absolutely need to: 2651 ;; DESERT-LIM. Only search what we absolutely need to,
2641 (if (and c-state-brace-pair-desert 2652 (let ((desert-lim
2642 (eq cache-pos (car c-state-brace-pair-desert))) 2653 (and c-state-brace-pair-desert
2643 (narrow-to-region (cdr c-state-brace-pair-desert) (point-max))) 2654 (eq cache-pos (car c-state-brace-pair-desert))
2655 (cdr c-state-brace-pair-desert)))
2656 ;; CACHE-LIM. This limit will be necessary when an opening
2657 ;; paren at `cache-pos' has just had its matching close paren
2658 ;; inserted. `cache-pos' continues to be a search bound, even
2659 ;; though the algorithm below would skip over the new paren
2660 ;; pair.
2661 (cache-lim (and cache-pos (< cache-pos from) cache-pos)))
2662 (narrow-to-region
2663 (cond
2664 ((and desert-lim cache-lim)
2665 (max desert-lim cache-lim))
2666 (desert-lim)
2667 (cache-lim)
2668 ((point-min)))
2669 (point-max)))
2644 2670
2645 ;; In the next pair of nested loops, the inner one moves back past a 2671 ;; In the next pair of nested loops, the inner one moves back past a
2646 ;; pair of (mis-)matching parens or brackets; the outer one moves 2672 ;; pair of (mis-)matching parens or brackets; the outer one moves
@@ -2674,7 +2700,7 @@ comment at the start of cc-engine.el for more info."
2674 (cons new-cons (cdr c-state-cache)))) 2700 (cons new-cons (cdr c-state-cache))))
2675 (t (setq c-state-cache (cons new-cons c-state-cache))))) 2701 (t (setq c-state-cache (cons new-cons c-state-cache)))))
2676 2702
2677 ;; We haven't found a brace pair. Record this. 2703 ;; We haven't found a brace pair. Record this in the cache.
2678 (setq c-state-brace-pair-desert (cons cache-pos from)))))))) 2704 (setq c-state-brace-pair-desert (cons cache-pos from))))))))
2679 2705
2680(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here) 2706(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here)
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 2608ba0b0c3..45986591499 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -209,7 +209,7 @@ of[ \t]+\"?\\([a-zA-Z]?:?[^\":\n]+\\)\"?:" 3 2 nil (1))
209 ;; due to matching filenames via \\(.*?\\). This might be faster. 209 ;; due to matching filenames via \\(.*?\\). This might be faster.
210 (maven 210 (maven
211 ;; Maven is a popular free software build tool for Java. 211 ;; Maven is a popular free software build tool for Java.
212 "\\([0-9]*[^0-9\n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\] " 1 2 3) 212 "\\([^ \n]\\(?:[^\n :]\\| [^-/\n]\\|:[^ \n]\\)*?\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\] " 1 2 3)
213 213
214 (jikes-line 214 (jikes-line
215 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)" 215 "^ *\\([0-9]+\\)\\.[ \t]+.*\n +\\(<-*>\n\\*\\*\\* \\(?:Error\\|Warnin\\(g\\)\\)\\)"
@@ -1068,14 +1068,14 @@ FMTS is a list of format specs for transforming the file name.
1068 end-marker loc end-loc) 1068 end-marker loc end-loc)
1069 (if (not (and marker (marker-buffer marker))) 1069 (if (not (and marker (marker-buffer marker)))
1070 (setq marker nil) ; no valid marker for this file 1070 (setq marker nil) ; no valid marker for this file
1071 (setq loc (or line 1)) ; normalize no linenumber to line 1 1071 (unless line (setq line 1)) ; normalize no linenumber to line 1
1072 (catch 'marker ; find nearest loc, at least one exists 1072 (catch 'marker ; find nearest loc, at least one exists
1073 (dolist (x (cddr (compilation--file-struct->loc-tree 1073 (dolist (x (cddr (compilation--file-struct->loc-tree
1074 file-struct))) ; Loop over remaining lines. 1074 file-struct))) ; Loop over remaining lines.
1075 (if (> (car x) loc) ; Still bigger. 1075 (if (> (car x) line) ; Still bigger.
1076 (setq marker-line x) 1076 (setq marker-line x)
1077 (if (> (- (or (car marker-line) 1) loc) 1077 (if (> (- (or (car marker-line) 1) line)
1078 (- loc (car x))) ; Current line is nearer. 1078 (- line (car x))) ; Current line is nearer.
1079 (setq marker-line x)) 1079 (setq marker-line x))
1080 (throw 'marker t)))) 1080 (throw 'marker t))))
1081 (setq marker (compilation--loc->marker (cadr marker-line)) 1081 (setq marker (compilation--loc->marker (cadr marker-line))
@@ -1093,15 +1093,15 @@ FMTS is a list of format specs for transforming the file name.
1093 (save-restriction 1093 (save-restriction
1094 (widen) 1094 (widen)
1095 (goto-char (marker-position marker)) 1095 (goto-char (marker-position marker))
1096 (when (or end-col end-line) 1096 ;; Set end-marker if appropriate and go to line.
1097 (if (not (or end-col end-line))
1098 (beginning-of-line (- line marker-line -1))
1097 (beginning-of-line (- (or end-line line) marker-line -1)) 1099 (beginning-of-line (- (or end-line line) marker-line -1))
1098 (if (or (null end-col) (< end-col 0)) 1100 (if (or (null end-col) (< end-col 0))
1099 (end-of-line) 1101 (end-of-line)
1100 (compilation-move-to-column end-col screen-columns)) 1102 (compilation-move-to-column end-col screen-columns))
1101 (setq end-marker (point-marker))) 1103 (setq end-marker (point-marker))
1102 (beginning-of-line (if end-line 1104 (when end-line (beginning-of-line (- line end-line -1))))
1103 (- line end-line -1)
1104 (- loc marker-line -1)))
1105 (if col 1105 (if col
1106 (compilation-move-to-column col screen-columns) 1106 (compilation-move-to-column col screen-columns)
1107 (forward-to-indentation 0)) 1107 (forward-to-indentation 0))
@@ -1884,6 +1884,9 @@ Runs `compilation-mode-hook' with `run-mode-hooks' (which see).
1884 (setq buffer-read-only t) 1884 (setq buffer-read-only t)
1885 (run-mode-hooks 'compilation-mode-hook)) 1885 (run-mode-hooks 'compilation-mode-hook))
1886 1886
1887;;;###autoload
1888(put 'define-compilation-mode 'doc-string-elt 3)
1889
1887(defmacro define-compilation-mode (mode name doc &rest body) 1890(defmacro define-compilation-mode (mode name doc &rest body)
1888 "This is like `define-derived-mode' without the PARENT argument. 1891 "This is like `define-derived-mode' without the PARENT argument.
1889The parent is always `compilation-mode' and the customizable `compilation-...' 1892The parent is always `compilation-mode' and the customizable `compilation-...'
@@ -2132,14 +2135,14 @@ and runs `compilation-filter-hook'."
2132 (if (or (eq (get-text-property ,limit 'compilation-message) 2135 (if (or (eq (get-text-property ,limit 'compilation-message)
2133 (get-text-property opt 'compilation-message)) 2136 (get-text-property opt 'compilation-message))
2134 (eq pt opt)) 2137 (eq pt opt))
2135 (error ,error compilation-error) 2138 (user-error ,error compilation-error)
2136 (setq pt ,limit))) 2139 (setq pt ,limit)))
2137 ;; prop 'compilation-message usually has 2 changes, on and off, so 2140 ;; prop 'compilation-message usually has 2 changes, on and off, so
2138 ;; re-search if off 2141 ;; re-search if off
2139 (or (setq msg (get-text-property pt 'compilation-message)) 2142 (or (setq msg (get-text-property pt 'compilation-message))
2140 (if (setq pt (,property-change pt 'compilation-message nil ,limit)) 2143 (if (setq pt (,property-change pt 'compilation-message nil ,limit))
2141 (setq msg (get-text-property pt 'compilation-message))) 2144 (setq msg (get-text-property pt 'compilation-message)))
2142 (error ,error compilation-error)) 2145 (user-error ,error compilation-error))
2143 (or (< (compilation--message->type msg) compilation-skip-threshold) 2146 (or (< (compilation--message->type msg) compilation-skip-threshold)
2144 (if different-file 2147 (if different-file
2145 (eq (prog1 last 2148 (eq (prog1 last
@@ -2660,9 +2663,6 @@ The file-structure looks like this:
2660 (if (eq v fs) (remhash k compilation-locs))) 2663 (if (eq v fs) (remhash k compilation-locs)))
2661 compilation-locs))) 2664 compilation-locs)))
2662 2665
2663(add-to-list 'debug-ignored-errors "\\`No more [-a-z ]+s yet\\'")
2664(add-to-list 'debug-ignored-errors "\\`Moved past last .*")
2665
2666;;; Compatibility with the old compile.el. 2666;;; Compatibility with the old compile.el.
2667 2667
2668(defvaralias 'compilation-last-buffer 'next-error-last-buffer) 2668(defvaralias 'compilation-last-buffer 'next-error-last-buffer)
diff --git a/lisp/progmodes/ebnf2ps.el b/lisp/progmodes/ebnf2ps.el
index 05c9e160ceb..b7cbdcc7018 100644
--- a/lisp/progmodes/ebnf2ps.el
+++ b/lisp/progmodes/ebnf2ps.el
@@ -1181,10 +1181,10 @@ Elements of ALIST that are not conses are ignored."
1181;;; Interface to the command system 1181;;; Interface to the command system
1182 1182
1183(defgroup postscript nil 1183(defgroup postscript nil
1184 "PostScript Group." 1184 "Printing with PostScript"
1185 :tag "PostScript" 1185 :tag "PostScript"
1186 :version "20" 1186 :version "20"
1187 :group 'emacs) 1187 :group 'environment)
1188 1188
1189 1189
1190(defgroup ebnf2ps nil 1190(defgroup ebnf2ps nil
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index d8a561340d3..2664b51eea9 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -1,4 +1,4 @@
1;;; etags.el --- etags facility for Emacs 1;;; etags.el --- etags facility for Emacs -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1985-1986, 1988-1989, 1992-1996, 1998, 2000-2012 3;; Copyright (C) 1985-1986, 1988-1989, 1992-1996, 1998, 2000-2012
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
@@ -554,11 +554,10 @@ Returns t if it visits a tags table, or nil if there are no more in the list."
554 (cond ((eq cont 'same) 554 (cond ((eq cont 'same)
555 ;; Use the ambient value of tags-file-name. 555 ;; Use the ambient value of tags-file-name.
556 (or tags-file-name 556 (or tags-file-name
557 (error "%s" 557 (user-error "%s"
558 (substitute-command-keys 558 (substitute-command-keys
559 (concat "No tags table in use; " 559 (concat "No tags table in use; "
560 "use \\[visit-tags-table] to select one"))))) 560 "use \\[visit-tags-table] to select one")))))
561
562 ((eq t cont) 561 ((eq t cont)
563 ;; Find the next table. 562 ;; Find the next table.
564 (if (tags-next-table) 563 (if (tags-next-table)
@@ -566,7 +565,6 @@ Returns t if it visits a tags table, or nil if there are no more in the list."
566 (while (and (not (or (get-file-buffer tags-file-name) 565 (while (and (not (or (get-file-buffer tags-file-name)
567 (file-exists-p tags-file-name))) 566 (file-exists-p tags-file-name)))
568 (tags-next-table))))) 567 (tags-next-table)))))
569
570 (t 568 (t
571 ;; Pick a table out of our hat. 569 ;; Pick a table out of our hat.
572 (tags-table-check-computed-list) ;Get it up to date, we might use it. 570 (tags-table-check-computed-list) ;Get it up to date, we might use it.
@@ -706,7 +704,8 @@ Returns t if it visits a tags table, or nil if there are no more in the list."
706 (kill-local-variable 'tags-file-name) 704 (kill-local-variable 'tags-file-name)
707 (if (eq local-tags-file-name tags-file-name) 705 (if (eq local-tags-file-name tags-file-name)
708 (setq tags-file-name nil)) 706 (setq tags-file-name nil))
709 (error "File %s is not a valid tags table" local-tags-file-name))))) 707 (user-error "File %s is not a valid tags table"
708 local-tags-file-name)))))
710 709
711(defun tags-reset-tags-tables () 710(defun tags-reset-tags-tables ()
712 "Reset tags state to cancel effect of any previous \\[visit-tags-table] or \\[find-tag]." 711 "Reset tags state to cancel effect of any previous \\[visit-tags-table] or \\[find-tag]."
@@ -781,7 +780,7 @@ tags table and its (recursively) included tags tables."
781 (setq tags-completion-table nil))))) 780 (setq tags-completion-table nil)))))
782 781
783(defun tags-lazy-completion-table () 782(defun tags-lazy-completion-table ()
784 (lexical-let ((buf (current-buffer))) 783 (let ((buf (current-buffer)))
785 (lambda (string pred action) 784 (lambda (string pred action)
786 (with-current-buffer buf 785 (with-current-buffer buf
787 (save-excursion 786 (save-excursion
@@ -831,7 +830,7 @@ If no tags table is loaded, do nothing and return nil."
831 (tags-lazy-completion-table) 830 (tags-lazy-completion-table)
832 nil nil nil nil default))) 831 nil nil nil nil default)))
833 (if (equal spec "") 832 (if (equal spec "")
834 (or default (error "There is no default tag")) 833 (or default (user-error "There is no default tag"))
835 spec))) 834 spec)))
836 835
837(defvar last-tag nil 836(defvar last-tag nil
@@ -886,7 +885,7 @@ See documentation of variable `tags-file-name'."
886 (if (eq '- next-p) 885 (if (eq '- next-p)
887 ;; Pop back to a previous location. 886 ;; Pop back to a previous location.
888 (if (ring-empty-p tags-location-ring) 887 (if (ring-empty-p tags-location-ring)
889 (error "No previous tag locations") 888 (user-error "No previous tag locations")
890 (let ((marker (ring-remove tags-location-ring 0))) 889 (let ((marker (ring-remove tags-location-ring 0)))
891 (prog1 890 (prog1
892 ;; Move to the saved location. 891 ;; Move to the saved location.
@@ -1150,8 +1149,8 @@ error message."
1150 (set-marker (car tag-lines-already-matched) nil nil) 1149 (set-marker (car tag-lines-already-matched) nil nil)
1151 (setq tag-lines-already-matched (cdr tag-lines-already-matched))) 1150 (setq tag-lines-already-matched (cdr tag-lines-already-matched)))
1152 (set-marker match-marker nil nil) 1151 (set-marker match-marker nil nil)
1153 (error "No %stags %s %s" (if first-search "" "more ") 1152 (user-error "No %stags %s %s" (if first-search "" "more ")
1154 matching pattern)) 1153 matching pattern))
1155 1154
1156 ;; Found a tag; extract location info. 1155 ;; Found a tag; extract location info.
1157 (beginning-of-line) 1156 (beginning-of-line)
@@ -1391,8 +1390,8 @@ hits the start of file."
1391 offset (* 3 offset))) ; expand search window 1390 offset (* 3 offset))) ; expand search window
1392 (or found 1391 (or found
1393 (re-search-forward pat nil t) 1392 (re-search-forward pat nil t)
1394 (error "Rerun etags: `%s' not found in %s" 1393 (user-error "Rerun etags: `%s' not found in %s"
1395 pat buffer-file-name))) 1394 pat buffer-file-name)))
1396 ;; Position point at the right place 1395 ;; Position point at the right place
1397 ;; if the search string matched an extra Ctrl-m at the beginning. 1396 ;; if the search string matched an extra Ctrl-m at the beginning.
1398 (and (eq selective-display t) 1397 (and (eq selective-display t)
@@ -1742,7 +1741,7 @@ if the file was newly read in, the value is the filename."
1742 (and novisit 1741 (and novisit
1743 (get-buffer " *next-file*") 1742 (get-buffer " *next-file*")
1744 (kill-buffer " *next-file*")) 1743 (kill-buffer " *next-file*"))
1745 (error "All files processed")) 1744 (user-error "All files processed"))
1746 (let* ((next (car next-file-list)) 1745 (let* ((next (car next-file-list))
1747 (buffer (get-file-buffer next)) 1746 (buffer (get-file-buffer next))
1748 (new (not buffer))) 1747 (new (not buffer)))
@@ -1775,9 +1774,9 @@ if the file was newly read in, the value is the filename."
1775 "Form for `tags-loop-continue' to eval to change one file.") 1774 "Form for `tags-loop-continue' to eval to change one file.")
1776 1775
1777(defvar tags-loop-scan 1776(defvar tags-loop-scan
1778 '(error "%s" 1777 '(user-error "%s"
1779 (substitute-command-keys 1778 (substitute-command-keys
1780 "No \\[tags-search] or \\[tags-query-replace] in progress")) 1779 "No \\[tags-search] or \\[tags-query-replace] in progress"))
1781 "Form for `tags-loop-continue' to eval to scan one file. 1780 "Form for `tags-loop-continue' to eval to scan one file.
1782If it returns non-nil, this file needs processing by evalling 1781If it returns non-nil, this file needs processing by evalling
1783\`tags-loop-operate'. Otherwise, move on to the next file.") 1782\`tags-loop-operate'. Otherwise, move on to the next file.")
@@ -1937,7 +1936,7 @@ directory specification."
1937 (if (funcall list-tags-function file) 1936 (if (funcall list-tags-function file)
1938 (setq gotany t))) 1937 (setq gotany t)))
1939 (or gotany 1938 (or gotany
1940 (error "File %s not in current tags tables" file))))) 1939 (user-error "File %s not in current tags tables" file)))))
1941 (with-current-buffer "*Tags List*" 1940 (with-current-buffer "*Tags List*"
1942 (require 'apropos) 1941 (require 'apropos)
1943 (with-no-warnings 1942 (with-no-warnings
@@ -2067,28 +2066,15 @@ for \\[find-tag] (which see)."
2067 (interactive) 2066 (interactive)
2068 (or tags-table-list 2067 (or tags-table-list
2069 tags-file-name 2068 tags-file-name
2070 (error "%s" 2069 (user-error "%s"
2071 (substitute-command-keys 2070 (substitute-command-keys
2072 "No tags table loaded; try \\[visit-tags-table]"))) 2071 "No tags table loaded; try \\[visit-tags-table]")))
2073 (let ((comp-data (tags-completion-at-point-function))) 2072 (let ((comp-data (tags-completion-at-point-function)))
2074 (if (null comp-data) 2073 (if (null comp-data)
2075 (error "Nothing to complete") 2074 (user-error "Nothing to complete")
2076 (completion-in-region (car comp-data) (cadr comp-data) 2075 (completion-in-region (car comp-data) (cadr comp-data)
2077 (nth 2 comp-data) 2076 (nth 2 comp-data)
2078 (plist-get (nthcdr 3 comp-data) :predicate))))) 2077 (plist-get (nthcdr 3 comp-data) :predicate)))))
2079
2080(dolist (x '("^No tags table in use; use .* to select one$"
2081 "^There is no default tag$"
2082 "^No previous tag locations$"
2083 "^File .* is not a valid tags table$"
2084 "^No \\(more \\|\\)tags \\(matching\\|containing\\) "
2085 "^Rerun etags: `.*' not found in "
2086 "^All files processed$"
2087 "^No .* or .* in progress$"
2088 "^File .* not in current tags tables$"
2089 "^No tags table loaded"
2090 "^Nothing to complete$"))
2091 (add-to-list 'debug-ignored-errors x))
2092 2078
2093(provide 'etags) 2079(provide 'etags)
2094 2080
diff --git a/lisp/progmodes/f90.el b/lisp/progmodes/f90.el
index 1d2beedd191..712725ffaf0 100644
--- a/lisp/progmodes/f90.el
+++ b/lisp/progmodes/f90.el
@@ -2204,18 +2204,13 @@ Leave point at the end of line."
2204 "Typing `\\[help-command] or `? lists all the F90 abbrevs. 2204 "Typing `\\[help-command] or `? lists all the F90 abbrevs.
2205Any other key combination is executed normally." 2205Any other key combination is executed normally."
2206 (interactive "*") 2206 (interactive "*")
2207 (insert last-command-event) 2207 (self-insert-command 1)
2208 (let (char event) 2208 (when abbrev-mode
2209 (if (fboundp 'next-command-event) ; XEmacs 2209 (set-temporary-overlay-map
2210 (setq event (next-command-event) 2210 (let ((map (make-sparse-keymap)))
2211 char (and (fboundp 'event-to-character) 2211 (define-key map [??] 'f90-abbrev-help)
2212 (event-to-character event))) 2212 (define-key map (vector help-char) 'f90-abbrev-help)
2213 (setq event (read-event) 2213 map))))
2214 char event))
2215 ;; Insert char if not equal to `?', or if abbrev-mode is off.
2216 (if (and abbrev-mode (memq char (list ?? help-char)))
2217 (f90-abbrev-help)
2218 (setq unread-command-events (list event)))))
2219 2214
2220(defun f90-abbrev-help () 2215(defun f90-abbrev-help ()
2221 "List the currently defined abbrevs in F90 mode." 2216 "List the currently defined abbrevs in F90 mode."
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index ed8eb81932e..96d4105f65b 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -253,7 +253,7 @@ are the string substitutions (see `format')."
253(make-variable-buffer-local 'flymake-output-residual) 253(make-variable-buffer-local 'flymake-output-residual)
254 254
255(defgroup flymake nil 255(defgroup flymake nil
256 "A universal on-the-fly syntax checker." 256 "Universal on-the-fly syntax checker."
257 :version "23.1" 257 :version "23.1"
258 :group 'tools) 258 :group 'tools)
259 259
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 1be74ff544b..5ea0f6a3fd2 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -459,9 +459,14 @@ Most recent commands are listed first. This list stores only the last
459`gdb-debug-log-max' values. This variable is used to debug GDB-MI.") 459`gdb-debug-log-max' values. This variable is used to debug GDB-MI.")
460 460
461;;;###autoload 461;;;###autoload
462(defcustom gdb-enable-debug nil 462(define-minor-mode gdb-enable-debug
463 "Non-nil means record the process input and output in `gdb-debug-log'." 463 "Toggle logging of transaction between Emacs and Gdb.
464 :type 'boolean 464The log is stored in `gdb-debug-log' as an alist with elements
465whose cons is send, send-item or recv and whose cdr is the string
466being transferred. This list may grow up to a size of
467`gdb-debug-log-max' after which the oldest element (at the end of
468the list) is deleted every time a new one is added (at the front)."
469 :global t
465 :group 'gdb 470 :group 'gdb
466 :version "22.1") 471 :version "22.1")
467 472
@@ -512,21 +517,6 @@ Also display the main routine in the disassembly buffer if present."
512 ;; Force mode line redisplay soon. 517 ;; Force mode line redisplay soon.
513 (force-mode-line-update))))) 518 (force-mode-line-update)))))
514 519
515(defun gdb-enable-debug (arg)
516 "Toggle logging of transaction between Emacs and Gdb.
517The log is stored in `gdb-debug-log' as an alist with elements
518whose cons is send, send-item or recv and whose cdr is the string
519being transferred. This list may grow up to a size of
520`gdb-debug-log-max' after which the oldest element (at the end of
521the list) is deleted every time a new one is added (at the front)."
522 (interactive "P")
523 (setq gdb-enable-debug
524 (if (null arg)
525 (not gdb-enable-debug)
526 (> (prefix-numeric-value arg) 0)))
527 (message (format "Logging of transaction %sabled"
528 (if gdb-enable-debug "en" "dis"))))
529
530;; These two are used for menu and toolbar 520;; These two are used for menu and toolbar
531(defun gdb-control-all-threads () 521(defun gdb-control-all-threads ()
532 "Switch to non-stop/A mode." 522 "Switch to non-stop/A mode."
@@ -603,6 +593,8 @@ NOARG must be t when this macro is used outside `gud-def'"
603 (set (make-local-variable 'gud-marker-filter) #'gud-gdb-marker-filter)) 593 (set (make-local-variable 'gud-marker-filter) #'gud-gdb-marker-filter))
604 (funcall filter proc string)))) 594 (funcall filter proc string))))
605 595
596(defvar gdb-control-level 0)
597
606;;;###autoload 598;;;###autoload
607(defun gdb (command-line) 599(defun gdb (command-line)
608 "Run gdb on program FILE in buffer *gud-FILE*. 600 "Run gdb on program FILE in buffer *gud-FILE*.
@@ -677,6 +669,7 @@ detailed description of this mode.
677 (set-process-filter proc #'gdb--check-interpreter)) 669 (set-process-filter proc #'gdb--check-interpreter))
678 670
679 (set (make-local-variable 'gud-minor-mode) 'gdbmi) 671 (set (make-local-variable 'gud-minor-mode) 'gdbmi)
672 (set (make-local-variable 'gdb-control-level) 0)
680 (setq comint-input-sender 'gdb-send) 673 (setq comint-input-sender 'gdb-send)
681 (when (ring-empty-p comint-input-ring) ; cf shell-mode 674 (when (ring-empty-p comint-input-ring) ; cf shell-mode
682 (let ((hfile (expand-file-name (or (getenv "GDBHISTFILE") 675 (let ((hfile (expand-file-name (or (getenv "GDBHISTFILE")
@@ -827,7 +820,7 @@ detailed description of this mode.
827 (run-hooks 'gdb-mode-hook)) 820 (run-hooks 'gdb-mode-hook))
828 821
829(defun gdb-init-1 () 822(defun gdb-init-1 ()
830 ;; (re-)initialize 823 ;; (Re-)initialize.
831 (setq gdb-selected-frame nil 824 (setq gdb-selected-frame nil
832 gdb-frame-number nil 825 gdb-frame-number nil
833 gdb-thread-number nil 826 gdb-thread-number nil
@@ -862,8 +855,13 @@ detailed description of this mode.
862 (gdb-clear-inferior-io) 855 (gdb-clear-inferior-io)
863 (gdb-inferior-io--init-proc (get-process "gdb-inferior")) 856 (gdb-inferior-io--init-proc (get-process "gdb-inferior"))
864 857
865 (if (eq window-system 'w32) 858 (when (eq system-type 'windows-nt)
866 (gdb-input "-gdb-set new-console off" 'ignore)) 859 ;; Don't create a separate console window for the debuggee.
860 (gdb-input "-gdb-set new-console off" 'ignore)
861 ;; Force GDB to behave as if its input and output stream were
862 ;; connected to a TTY device (since on Windows we use pipes for
863 ;; communicating with GDB).
864 (gdb-input "-gdb-set interactive-mode on" 'ignore))
867 (gdb-input "-gdb-set height 0" 'ignore) 865 (gdb-input "-gdb-set height 0" 'ignore)
868 866
869 (when gdb-non-stop 867 (when gdb-non-stop
@@ -871,7 +869,7 @@ detailed description of this mode.
871 869
872 (gdb-input "-enable-pretty-printing" 'ignore) 870 (gdb-input "-enable-pretty-printing" 'ignore)
873 871
874 ;; find source file and compilation directory here 872 ;; Find source file and compilation directory here.
875 (if gdb-create-source-file-list 873 (if gdb-create-source-file-list
876 ;; Needs GDB 6.2 onwards. 874 ;; Needs GDB 6.2 onwards.
877 (gdb-input "-file-list-exec-source-files" 'gdb-get-source-file-list)) 875 (gdb-input "-file-list-exec-source-files" 'gdb-get-source-file-list))
@@ -971,15 +969,17 @@ no input, and GDB is waiting for input."
971 (gdb-create-define-alist) 969 (gdb-create-define-alist)
972 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))) 970 (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))
973 971
974(defmacro gdb-if-arrow (arrow-position &rest body) 972(defmacro gdb--if-arrow (arrow-position start-posn end-posn &rest body)
975 `(if ,arrow-position 973 (declare (indent 3))
976 (let ((buffer (marker-buffer ,arrow-position)) (line)) 974 (let ((buffer (make-symbol "buffer")))
977 (if (equal buffer (window-buffer (posn-window end))) 975 `(if ,arrow-position
978 (with-current-buffer buffer 976 (let ((,buffer (marker-buffer ,arrow-position)))
979 (when (or (equal start end) 977 (if (equal ,buffer (window-buffer (posn-window ,end-posn)))
980 (equal (posn-point start) 978 (with-current-buffer ,buffer
981 (marker-position ,arrow-position))) 979 (when (or (equal ,start-posn ,end-posn)
982 ,@body)))))) 980 (equal (posn-point ,start-posn)
981 (marker-position ,arrow-position)))
982 ,@body)))))))
983 983
984(defun gdb-mouse-until (event) 984(defun gdb-mouse-until (event)
985 "Continue running until a source line past the current line. 985 "Continue running until a source line past the current line.
@@ -989,15 +989,15 @@ with mouse-1 (default bindings)."
989 (interactive "e") 989 (interactive "e")
990 (let ((start (event-start event)) 990 (let ((start (event-start event))
991 (end (event-end event))) 991 (end (event-end event)))
992 (gdb-if-arrow gud-overlay-arrow-position 992 (gdb--if-arrow gud-overlay-arrow-position start end
993 (setq line (line-number-at-pos (posn-point end))) 993 (let ((line (line-number-at-pos (posn-point end))))
994 (gud-call (concat "until " (number-to-string line)))) 994 (gud-call (concat "until " (number-to-string line)))))
995 (gdb-if-arrow gdb-disassembly-position 995 (gdb--if-arrow gdb-disassembly-position start end
996 (save-excursion 996 (save-excursion
997 (goto-char (point-min)) 997 (goto-char (point-min))
998 (forward-line (1- (line-number-at-pos (posn-point end)))) 998 (forward-line (1- (line-number-at-pos (posn-point end))))
999 (forward-char 2) 999 (forward-char 2)
1000 (gud-call (concat "until *%a")))))) 1000 (gud-call (concat "until *%a"))))))
1001 1001
1002(defun gdb-mouse-jump (event) 1002(defun gdb-mouse-jump (event)
1003 "Set execution address/line. 1003 "Set execution address/line.
@@ -1008,19 +1008,17 @@ line, and no execution takes place."
1008 (interactive "e") 1008 (interactive "e")
1009 (let ((start (event-start event)) 1009 (let ((start (event-start event))
1010 (end (event-end event))) 1010 (end (event-end event)))
1011 (gdb-if-arrow gud-overlay-arrow-position 1011 (gdb--if-arrow gud-overlay-arrow-position start end
1012 (setq line (line-number-at-pos (posn-point end))) 1012 (let ((line (line-number-at-pos (posn-point end))))
1013 (progn 1013 (gud-call (concat "tbreak " (number-to-string line)))
1014 (gud-call (concat "tbreak " (number-to-string line))) 1014 (gud-call (concat "jump " (number-to-string line)))))
1015 (gud-call (concat "jump " (number-to-string line))))) 1015 (gdb--if-arrow gdb-disassembly-position start end
1016 (gdb-if-arrow gdb-disassembly-position 1016 (save-excursion
1017 (save-excursion 1017 (goto-char (point-min))
1018 (goto-char (point-min)) 1018 (forward-line (1- (line-number-at-pos (posn-point end))))
1019 (forward-line (1- (line-number-at-pos (posn-point end)))) 1019 (forward-char 2)
1020 (forward-char 2) 1020 (gud-call (concat "tbreak *%a"))
1021 (progn 1021 (gud-call (concat "jump *%a"))))))
1022 (gud-call (concat "tbreak *%a"))
1023 (gud-call (concat "jump *%a")))))))
1024 1022
1025(defcustom gdb-show-changed-values t 1023(defcustom gdb-show-changed-values t
1026 "If non-nil change the face of out of scope variables and changed values. 1024 "If non-nil change the face of out of scope variables and changed values.
@@ -1042,10 +1040,11 @@ Changed values are highlighted with the face `font-lock-warning-face'."
1042 :group 'gdb 1040 :group 'gdb
1043 :version "22.2") 1041 :version "22.2")
1044 1042
1045(defcustom gdb-speedbar-auto-raise nil 1043(define-minor-mode gdb-speedbar-auto-raise
1046 "If non-nil raise speedbar every time display of watch expressions is\ 1044 "Minor mode to automatically raise the speedbar for watch expressions.
1047 updated." 1045With prefix argument ARG, automatically raise speedbar if ARG is
1048 :type 'boolean 1046positive, otherwise don't automatically raise it."
1047 :global t
1049 :group 'gdb 1048 :group 'gdb
1050 :version "22.1") 1049 :version "22.1")
1051 1050
@@ -1055,18 +1054,6 @@ Changed values are highlighted with the face `font-lock-warning-face'."
1055 :group 'gdb 1054 :group 'gdb
1056 :version "22.1") 1055 :version "22.1")
1057 1056
1058(defun gdb-speedbar-auto-raise (arg)
1059 "Toggle automatic raising of the speedbar for watch expressions.
1060With prefix argument ARG, automatically raise speedbar if ARG is
1061positive, otherwise don't automatically raise it."
1062 (interactive "P")
1063 (setq gdb-speedbar-auto-raise
1064 (if (null arg)
1065 (not gdb-speedbar-auto-raise)
1066 (> (prefix-numeric-value arg) 0)))
1067 (message (format "Auto raising %sabled"
1068 (if gdb-speedbar-auto-raise "en" "dis"))))
1069
1070(define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch) 1057(define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
1071(define-key global-map (vconcat gud-key-prefix "\C-w") 'gud-watch) 1058(define-key global-map (vconcat gud-key-prefix "\C-w") 'gud-watch)
1072 1059
@@ -1204,8 +1191,8 @@ With arg, enter name of variable to be watched in the minibuffer."
1204(defun gdb-edit-value (_text _token _indent) 1191(defun gdb-edit-value (_text _token _indent)
1205 "Assign a value to a variable displayed in the speedbar." 1192 "Assign a value to a variable displayed in the speedbar."
1206 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list)) 1193 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
1207 (varnum (car var)) (value)) 1194 (varnum (car var))
1208 (setq value (read-string "New value: ")) 1195 (value (read-string "New value: ")))
1209 (gdb-input (concat "-var-assign " varnum " " value) 1196 (gdb-input (concat "-var-assign " varnum " " value)
1210 `(lambda () (gdb-edit-value-handler ,value))))) 1197 `(lambda () (gdb-edit-value-handler ,value)))))
1211 1198
@@ -1700,6 +1687,16 @@ static char *magick[] = {
1700 :group 'gdb) 1687 :group 'gdb)
1701 1688
1702 1689
1690(defvar gdb-control-commands-regexp
1691 (concat
1692 "^\\("
1693 "commands\\|if\\|while\\|define\\|document\\|python\\|"
1694 "while-stepping\\|stepping\\|ws\\|actions"
1695 "\\)\\([[:blank:]]+.*\\)?$")
1696 "Regexp matching GDB commands that enter a recursive reading loop.
1697As long as GDB is in the recursive reading loop, it does not expect
1698commands to be prefixed by \"-interpreter-exec console\".")
1699
1703(defun gdb-send (proc string) 1700(defun gdb-send (proc string)
1704 "A comint send filter for gdb." 1701 "A comint send filter for gdb."
1705 (with-current-buffer gud-comint-buffer 1702 (with-current-buffer gud-comint-buffer
@@ -1709,11 +1706,15 @@ static char *magick[] = {
1709 (if (not (string= "" string)) 1706 (if (not (string= "" string))
1710 (setq gdb-last-command string) 1707 (setq gdb-last-command string)
1711 (if gdb-last-command (setq string gdb-last-command))) 1708 (if gdb-last-command (setq string gdb-last-command)))
1712 (if (string-match "^-" string) 1709 (if (or (string-match "^-" string)
1713 ;; MI command 1710 (> gdb-control-level 0))
1711 ;; Either MI command or we are feeding GDB's recursive reading loop.
1714 (progn 1712 (progn
1715 (setq gdb-first-done-or-error t) 1713 (setq gdb-first-done-or-error t)
1716 (process-send-string proc (concat string "\n"))) 1714 (process-send-string proc (concat string "\n"))
1715 (if (and (string-match "^end$" string)
1716 (> gdb-control-level 0))
1717 (setq gdb-control-level (1- gdb-control-level))))
1717 ;; CLI command 1718 ;; CLI command
1718 (if (string-match "\\\\$" string) 1719 (if (string-match "\\\\$" string)
1719 (setq gdb-continuation (concat gdb-continuation string "\n")) 1720 (setq gdb-continuation (concat gdb-continuation string "\n"))
@@ -1724,7 +1725,12 @@ static char *magick[] = {
1724 (if gdb-enable-debug 1725 (if gdb-enable-debug
1725 (push (cons 'mi-send to-send) gdb-debug-log)) 1726 (push (cons 'mi-send to-send) gdb-debug-log))
1726 (process-send-string proc to-send)) 1727 (process-send-string proc to-send))
1727 (setq gdb-continuation nil)))) 1728 (if (and (string-match "^end$" string)
1729 (> gdb-control-level 0))
1730 (setq gdb-control-level (1- gdb-control-level)))
1731 (setq gdb-continuation nil)))
1732 (if (string-match gdb-control-commands-regexp string)
1733 (setq gdb-control-level (1+ gdb-control-level))))
1728 1734
1729(defun gdb-mi-quote (string) 1735(defun gdb-mi-quote (string)
1730 "Return STRING quoted properly as an MI argument. 1736 "Return STRING quoted properly as an MI argument.
@@ -1838,7 +1844,7 @@ is running."
1838 (setq gud-running 1844 (setq gud-running
1839 (string= (bindat-get-field (gdb-current-buffer-thread) 'state) 1845 (string= (bindat-get-field (gdb-current-buffer-thread) 'state)
1840 "running")) 1846 "running"))
1841 ;; Set frame number to "0" when _current_ threads stops 1847 ;; Set frame number to "0" when _current_ threads stops.
1842 (when (and (gdb-current-buffer-thread) 1848 (when (and (gdb-current-buffer-thread)
1843 (not (eq gud-running old-value))) 1849 (not (eq gud-running old-value)))
1844 (setq gdb-frame-number "0")))) 1850 (setq gdb-frame-number "0"))))
@@ -1906,10 +1912,10 @@ is running."
1906 (> (length gdb-debug-log) gdb-debug-log-max)) 1912 (> (length gdb-debug-log) gdb-debug-log-max))
1907 (setcdr (nthcdr (1- gdb-debug-log-max) gdb-debug-log) nil))) 1913 (setcdr (nthcdr (1- gdb-debug-log-max) gdb-debug-log) nil)))
1908 1914
1909 ;; Recall the left over gud-marker-acc from last time 1915 ;; Recall the left over gud-marker-acc from last time.
1910 (setq gud-marker-acc (concat gud-marker-acc string)) 1916 (setq gud-marker-acc (concat gud-marker-acc string))
1911 1917
1912 ;; Start accumulating output for the GUD buffer 1918 ;; Start accumulating output for the GUD buffer.
1913 (setq gdb-filter-output "") 1919 (setq gdb-filter-output "")
1914 (let (output-record-list) 1920 (let (output-record-list)
1915 1921
@@ -1955,9 +1961,8 @@ is running."
1955(defun gdb-gdb (_output-field)) 1961(defun gdb-gdb (_output-field))
1956 1962
1957(defun gdb-shell (output-field) 1963(defun gdb-shell (output-field)
1958 (let ((gdb-output-sink gdb-output-sink)) 1964 (setq gdb-filter-output
1959 (setq gdb-filter-output 1965 (concat output-field gdb-filter-output)))
1960 (concat output-field gdb-filter-output))))
1961 1966
1962(defun gdb-ignored-notification (_output-field)) 1967(defun gdb-ignored-notification (_output-field))
1963 1968
@@ -2041,14 +2046,15 @@ current thread and update GDB buffers."
2041 (concat " --thread " thread-id))) 2046 (concat " --thread " thread-id)))
2042 'gdb-register-names-handler)) 2047 'gdb-register-names-handler))
2043 2048
2044;;; Don't set gud-last-frame here as it's currently done in gdb-frame-handler 2049 ;; Don't set gud-last-frame here as it's currently done in
2045;;; because synchronous GDB doesn't give these fields with CLI. 2050 ;; gdb-frame-handler because synchronous GDB doesn't give these fields
2046;;; (when file 2051 ;; with CLI.
2047;;; (setq 2052 ;;(when file
2048;;; ;; Extract the frame position from the marker. 2053 ;; (setq
2049;;; gud-last-frame (cons file 2054 ;; ;; Extract the frame position from the marker.
2050;;; (string-to-number 2055 ;; gud-last-frame (cons file
2051;;; (match-string 6 gud-marker-acc))))) 2056 ;; (string-to-number
2057 ;; (match-string 6 gud-marker-acc)))))
2052 2058
2053 (setq gdb-inferior-status (or reason "unknown")) 2059 (setq gdb-inferior-status (or reason "unknown"))
2054 (gdb-force-mode-line-update 2060 (gdb-force-mode-line-update
@@ -2332,8 +2338,9 @@ calling `gdb-table-string'."
2332(defun gdb-get-many-fields (struct &rest fields) 2338(defun gdb-get-many-fields (struct &rest fields)
2333 "Return a list of FIELDS values from STRUCT." 2339 "Return a list of FIELDS values from STRUCT."
2334 (let ((values)) 2340 (let ((values))
2335 (dolist (field fields values) 2341 (dolist (field fields)
2336 (setq values (append values (list (bindat-get-field struct field))))))) 2342 (push (bindat-get-field struct field) values))
2343 (nreverse values)))
2337 2344
2338(defmacro def-gdb-auto-update-trigger (trigger-name gdb-command 2345(defmacro def-gdb-auto-update-trigger (trigger-name gdb-command
2339 handler-name 2346 handler-name
@@ -4107,31 +4114,19 @@ window is dedicated."
4107 nil win5)) 4114 nil win5))
4108 (select-window win0))) 4115 (select-window win0)))
4109 4116
4110(defcustom gdb-many-windows nil 4117(define-minor-mode gdb-many-windows
4111 "If nil just pop up the GUD buffer unless `gdb-show-main' is t. 4118 "If nil just pop up the GUD buffer unless `gdb-show-main' is t.
4112In this case it starts with two windows: one displaying the GUD 4119In this case it starts with two windows: one displaying the GUD
4113buffer and the other with the source file with the main routine 4120buffer and the other with the source file with the main routine
4114of the debugged program. Non-nil means display the layout shown for 4121of the debugged program. Non-nil means display the layout shown for
4115`gdb'." 4122`gdb'."
4116 :type 'boolean 4123 :global t
4117 :group 'gdb 4124 :group 'gdb
4118 :version "22.1") 4125 :version "22.1"
4119
4120(defun gdb-many-windows (arg)
4121 "Toggle the number of windows in the basic arrangement.
4122With arg, display additional buffers iff arg is positive."
4123 (interactive "P")
4124 (setq gdb-many-windows
4125 (if (null arg)
4126 (not gdb-many-windows)
4127 (> (prefix-numeric-value arg) 0)))
4128 (message (format "Display of other windows %sabled"
4129 (if gdb-many-windows "en" "dis")))
4130 (if (and gud-comint-buffer 4126 (if (and gud-comint-buffer
4131 (buffer-name gud-comint-buffer)) 4127 (buffer-name gud-comint-buffer))
4132 (condition-case nil 4128 (ignore-errors
4133 (gdb-restore-windows) 4129 (gdb-restore-windows))))
4134 (error nil))))
4135 4130
4136(defun gdb-restore-windows () 4131(defun gdb-restore-windows ()
4137 "Restore the basic arrangement of windows used by gdb. 4132 "Restore the basic arrangement of windows used by gdb.
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 1f60c351252..7123a8dd7fc 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -58,8 +58,9 @@
58;; GUD commands must be visible in C buffers visited by GUD 58;; GUD commands must be visible in C buffers visited by GUD
59 59
60(defgroup gud nil 60(defgroup gud nil
61 "Grand Unified Debugger mode for gdb and other debuggers under Emacs. 61 "The \"Grand Unified Debugger\" interface.
62Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python) and jdb." 62Supported debuggers include gdb, sdb, dbx, xdb, perldb,
63pdb (Python), and jdb."
63 :group 'processes 64 :group 'processes
64 :group 'tools) 65 :group 'tools)
65 66
diff --git a/lisp/progmodes/idlw-shell.el b/lisp/progmodes/idlw-shell.el
index d843de04913..da8f30bab43 100644
--- a/lisp/progmodes/idlw-shell.el
+++ b/lisp/progmodes/idlw-shell.el
@@ -183,12 +183,6 @@ so that the name will be unique among multiple Emacs processes."
183 :group 'idlwave-shell-general-setup 183 :group 'idlwave-shell-general-setup
184 :type 'string) 184 :type 'string)
185 185
186(defvar idlwave-shell-fix-inserted-breaks nil
187 "OBSOLETE VARIABLE, is no longer used.
188
189The documentation of this variable used to be:
190If non-nil then run `idlwave-shell-remove-breaks' to clean up IDL messages.")
191
192(defcustom idlwave-shell-prefix-key "\C-c\C-d" 186(defcustom idlwave-shell-prefix-key "\C-c\C-d"
193 "The prefix key for the debugging map `idlwave-shell-mode-prefix-map'. 187 "The prefix key for the debugging map `idlwave-shell-mode-prefix-map'.
194This variable must already be set when idlwave-shell.el is loaded. 188This variable must already be set when idlwave-shell.el is loaded.
@@ -223,9 +217,6 @@ window, but is useful for stepping, etc."
223 217
224;; (defcustom idlwave-shell-debug-modifiers... See idlwave.el 218;; (defcustom idlwave-shell-debug-modifiers... See idlwave.el
225 219
226(defvar idlwave-shell-activate-alt-keybindings nil
227 "Obsolete variable. See `idlwave-shell-debug-modifiers'.")
228
229(defcustom idlwave-shell-use-truename nil 220(defcustom idlwave-shell-use-truename nil
230 "Non-nil means, use `file-truename' when looking for buffers. 221 "Non-nil means, use `file-truename' when looking for buffers.
231If this variable is non-nil, Emacs will use the function `file-truename' to 222If this variable is non-nil, Emacs will use the function `file-truename' to
@@ -335,9 +326,6 @@ expression being examined."
335 (string :tag "Label ") 326 (string :tag "Label ")
336 (string :tag "Command")))) 327 (string :tag "Command"))))
337 328
338(defvar idlwave-shell-print-expression-function nil
339 "OBSOLETE VARIABLE, is no longer used.")
340
341(defcustom idlwave-shell-separate-examine-output t 329(defcustom idlwave-shell-separate-examine-output t
342 "Non-nil means, put output of examine commands in their own buffer." 330 "Non-nil means, put output of examine commands in their own buffer."
343 :group 'idlwave-shell-command-setup 331 :group 'idlwave-shell-command-setup
@@ -520,9 +508,6 @@ t Glyph when possible, otherwise face (same effect as 'glyph)."
520 (const :tag "Display glyph (red dot)" glyph) 508 (const :tag "Display glyph (red dot)" glyph)
521 (const :tag "Glyph or face." t))) 509 (const :tag "Glyph or face." t)))
522 510
523(defvar idlwave-shell-use-breakpoint-glyph t
524 "Obsolete variable. See `idlwave-shell-mark-breakpoints'.")
525
526(defcustom idlwave-shell-breakpoint-face 'idlwave-shell-bp 511(defcustom idlwave-shell-breakpoint-face 'idlwave-shell-bp
527 "The face for breakpoint lines in the source code. 512 "The face for breakpoint lines in the source code.
528Allows you to choose the font, color and other properties for 513Allows you to choose the font, color and other properties for
@@ -4198,12 +4183,8 @@ Otherwise, just expand the file name."
4198 ([( ?[)] ?[ idlwave-shell-goto-previous-bp t t) 4183 ([( ?[)] ?[ idlwave-shell-goto-previous-bp t t)
4199 ([( ?])] ?] idlwave-shell-goto-next-bp t t) 4184 ([( ?])] ?] idlwave-shell-goto-next-bp t t)
4200 ([(control ?f)] ?f idlwave-shell-window))) 4185 ([(control ?f)] ?f idlwave-shell-window)))
4201 (mod (cond ((and idlwave-shell-debug-modifiers 4186 (mod (and (listp idlwave-shell-debug-modifiers)
4202 (listp idlwave-shell-debug-modifiers) 4187 idlwave-shell-debug-modifiers))
4203 (not (equal '() idlwave-shell-debug-modifiers)))
4204 idlwave-shell-debug-modifiers)
4205 (idlwave-shell-activate-alt-keybindings
4206 '(alt))))
4207 (shift (memq 'shift mod)) 4188 (shift (memq 'shift mod))
4208 (mod-noshift (delete 'shift (copy-sequence mod))) 4189 (mod-noshift (delete 'shift (copy-sequence mod)))
4209 s k1 c2 k2 cmd electric only-buffer cannotshift) 4190 s k1 c2 k2 cmd electric only-buffer cannotshift)
diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el
index 74f37df9b2d..015f58df3fb 100644
--- a/lisp/progmodes/idlwave.el
+++ b/lisp/progmodes/idlwave.el
@@ -456,9 +456,6 @@ value of `!DIR'. See also `idlwave-library-path'."
456(defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el") 456(defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
457(defvar idlwave-path-file "idlpath.el") 457(defvar idlwave-path-file "idlpath.el")
458 458
459(defvar idlwave-libinfo-file nil
460 "Obsolete variable, no longer used.")
461
462(defcustom idlwave-special-lib-alist nil 459(defcustom idlwave-special-lib-alist nil
463 "Alist of regular expressions matching special library directories. 460 "Alist of regular expressions matching special library directories.
464When listing routine source locations, IDLWAVE gives a short hint where 461When listing routine source locations, IDLWAVE gives a short hint where
@@ -555,10 +552,6 @@ completions."
555 :group 'idlwave-completion 552 :group 'idlwave-completion
556 :type 'boolean) 553 :type 'boolean)
557 554
558(defvar idlwave-default-completion-case-is-down nil
559 "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
560`idlwave-completion-case'.")
561
562(defcustom idlwave-buffer-case-takes-precedence nil 555(defcustom idlwave-buffer-case-takes-precedence nil
563 "Non-nil means, the case of tokens in buffers dominates over system stuff. 556 "Non-nil means, the case of tokens in buffers dominates over system stuff.
564To make this possible, we need to re-case everything each time we update 557To make this possible, we need to re-case everything each time we update
@@ -4525,8 +4518,6 @@ information updated immediately, leave NO-CONCATENATE nil."
4525 nil 'idlwave-load-rinfo-next-step))) 4518 nil 'idlwave-load-rinfo-next-step)))
4526 (error nil)))) 4519 (error nil))))
4527 4520
4528(defvar idlwave-library-routines nil "Obsolete variable.")
4529
4530;;------ XML Help routine info system 4521;;------ XML Help routine info system
4531(defun idlwave-load-system-routine-info () 4522(defun idlwave-load-system-routine-info ()
4532 ;; Load the system routine info from the cached routine info file, 4523 ;; Load the system routine info from the cached routine info file,
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 69da6737520..cdc3ef1c2e0 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1,4 +1,4 @@
1;;; js.el --- Major mode for editing JavaScript 1;;; js.el --- Major mode for editing JavaScript -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 2008-2012 Free Software Foundation, Inc. 3;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 4
@@ -1036,17 +1036,12 @@ LIMIT defaults to point."
1036 1036
1037 (c-save-buffer-state 1037 (c-save-buffer-state
1038 (open-items 1038 (open-items
1039 orig-match-start
1040 orig-match-end
1041 orig-depth
1042 parse 1039 parse
1043 prev-parse-point 1040 prev-parse-point
1044 name 1041 name
1045 case-fold-search 1042 case-fold-search
1046 filtered-class-styles 1043 filtered-class-styles
1047 new-item 1044 goal-point)
1048 goal-point
1049 end-prop)
1050 1045
1051 ;; Figure out which class styles we need to look for 1046 ;; Figure out which class styles we need to look for
1052 (setq filtered-class-styles 1047 (setq filtered-class-styles
@@ -1651,6 +1646,11 @@ This performs fontification according to `js--class-styles'."
1651 (funcall 1646 (funcall
1652 (syntax-propertize-rules 1647 (syntax-propertize-rules
1653 ;; Distinguish /-division from /-regexp chars (and from /-comment-starter). 1648 ;; Distinguish /-division from /-regexp chars (and from /-comment-starter).
1649 ;; FIXME: Allow regexps after infix ops like + ...
1650 ;; https://developer.mozilla.org/en/JavaScript/Reference/Operators
1651 ;; We can probably just add +, -, !, <, >, %, ^, ~, |, &, ?, : at which
1652 ;; point I think only * and / would be missing which could also be added,
1653 ;; but need care to avoid affecting the // and */ comment markers.
1654 ("\\(?:^\\|[=([{,:;]\\)\\(?:[ \t]\\)*\\(/\\)[^/*]" 1654 ("\\(?:^\\|[=([{,:;]\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
1655 (1 (ignore 1655 (1 (ignore
1656 (forward-char -1) 1656 (forward-char -1)
@@ -2956,8 +2956,8 @@ browser, respectively."
2956 (ido-mode -1)) 2956 (ido-mode -1))
2957 2957
2958 (with-js 2958 (with-js
2959 (lexical-let ((tabs (js--get-tabs)) selected-tab-cname 2959 (let ((tabs (js--get-tabs)) selected-tab-cname
2960 selected-tab prev-hitab) 2960 selected-tab prev-hitab)
2961 2961
2962 ;; Disambiguate names 2962 ;; Disambiguate names
2963 (setq tabs (loop with tab-names = (make-hash-table :test 'equal) 2963 (setq tabs (loop with tab-names = (make-hash-table :test 'equal)
@@ -3053,7 +3053,6 @@ browser, respectively."
3053 "gBrowser" 3053 "gBrowser"
3054 "selectedTab") 3054 "selectedTab")
3055 3055
3056 with index = 0
3057 for match in ido-matches 3056 for match in ido-matches
3058 for candidate-tab = (find-tab-by-cname match) 3057 for candidate-tab = (find-tab-by-cname match)
3059 if (eq (fourth candidate-tab) tab-to-match) 3058 if (eq (fourth candidate-tab) tab-to-match)
@@ -3330,7 +3329,7 @@ If one hasn't been set, or if it's stale, prompt for a new one."
3330 comment-start-skip "\\(//+\\|/\\*+\\)\\s *") 3329 comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
3331 3330
3332 (set (make-local-variable 'electric-indent-chars) 3331 (set (make-local-variable 'electric-indent-chars)
3333 (append "{}():;," electric-indent-chars)) 3332 (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
3334 (set (make-local-variable 'electric-layout-rules) 3333 (set (make-local-variable 'electric-layout-rules)
3335 '((?\; . after) (?\{ . after) (?\} . before))) 3334 '((?\; . after) (?\{ . after) (?\} . before)))
3336 3335
diff --git a/lisp/progmodes/make-mode.el b/lisp/progmodes/make-mode.el
index a173b11500e..2f4419ba2ea 100644
--- a/lisp/progmodes/make-mode.el
+++ b/lisp/progmodes/make-mode.el
@@ -1493,7 +1493,6 @@ Insertion takes place at point."
1493 (setq buffer-read-only t)) 1493 (setq buffer-read-only t))
1494 1494
1495(defun makefile-browse (targets macros) 1495(defun makefile-browse (targets macros)
1496 (interactive)
1497 (if (zerop (+ (length targets) (length macros))) 1496 (if (zerop (+ (length targets) (length macros)))
1498 (progn 1497 (progn
1499 (beep) 1498 (beep)
diff --git a/lisp/progmodes/meta-mode.el b/lisp/progmodes/meta-mode.el
index d0432f58d60..9978ee62687 100644
--- a/lisp/progmodes/meta-mode.el
+++ b/lisp/progmodes/meta-mode.el
@@ -829,6 +829,7 @@ The environment marked is the one that contains point or follows point."
829 st) 829 st)
830 "Syntax table used in Metafont or MetaPost mode.") 830 "Syntax table used in Metafont or MetaPost mode.")
831 831
832(define-obsolete-variable-alias 'meta-mode-map 'meta-common-mode-map "24.1")
832(defvar meta-common-mode-map 833(defvar meta-common-mode-map
833 (let ((map (make-sparse-keymap))) 834 (let ((map (make-sparse-keymap)))
834 ;; Comment Paragraphs: 835 ;; Comment Paragraphs:
@@ -858,7 +859,6 @@ The environment marked is the one that contains point or follows point."
858 ;; (define-key map "\C-c\C-l" 'meta-recenter-output) 859 ;; (define-key map "\C-c\C-l" 'meta-recenter-output)
859 map) 860 map)
860 "Keymap used in Metafont or MetaPost mode.") 861 "Keymap used in Metafont or MetaPost mode.")
861(define-obsolete-variable-alias 'meta-mode-map 'meta-common-mode-map "24.1")
862 862
863(easy-menu-define 863(easy-menu-define
864 meta-mode-menu meta-common-mode-map 864 meta-mode-menu meta-common-mode-map
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el
index 7091a9468c5..79b3fcee720 100644
--- a/lisp/progmodes/octave-mod.el
+++ b/lisp/progmodes/octave-mod.el
@@ -989,18 +989,13 @@ If Abbrev mode is turned on, typing ` (grave accent) followed by ? or
989executed normally. 989executed normally.
990Note that all Octave mode abbrevs start with a grave accent." 990Note that all Octave mode abbrevs start with a grave accent."
991 (interactive) 991 (interactive)
992 (if (not abbrev-mode) 992 (self-insert-command 1)
993 (self-insert-command 1) 993 (when abbrev-mode
994 (let (c) 994 (set-temporary-overlay-map
995 (insert last-command-event) 995 (let ((map (make-sparse-keymap)))
996 (if (if (featurep 'xemacs) 996 (define-key map [??] 'list-abbrevs)
997 (or (eq (event-to-character (setq c (next-event))) ??) 997 (define-key map (vector help-char) 'list-abbrevs)
998 (eq (event-to-character c) help-char)) 998 map))))
999 (or (eq (setq c (read-event)) ??)
1000 (eq c help-char)))
1001 (let ((abbrev-table-name-list '(octave-abbrev-table)))
1002 (list-abbrevs))
1003 (setq unread-command-events (list c))))))
1004 999
1005(define-skeleton octave-insert-defun 1000(define-skeleton octave-insert-defun
1006 "Insert an Octave function skeleton. 1001 "Insert an Octave function skeleton.
diff --git a/lisp/progmodes/pascal.el b/lisp/progmodes/pascal.el
index 8f7f313753c..62ba9418ced 100644
--- a/lisp/progmodes/pascal.el
+++ b/lisp/progmodes/pascal.el
@@ -467,6 +467,8 @@ no args, if that value is non-nil."
467;;; 467;;;
468;;; Interactive functions 468;;; Interactive functions
469;;; 469;;;
470(defvar pascal--extra-indent 0)
471
470(defun pascal-insert-block () 472(defun pascal-insert-block ()
471 "Insert Pascal begin ... end; block in the code with right indentation." 473 "Insert Pascal begin ... end; block in the code with right indentation."
472 (interactive) 474 (interactive)
@@ -757,14 +759,14 @@ on the line which ends a function or procedure named NAME."
757;;; Indentation 759;;; Indentation
758;;; 760;;;
759(defconst pascal-indent-alist 761(defconst pascal-indent-alist
760 '((block . (+ ind pascal-indent-level)) 762 '((block . (+ pascal--extra-indent pascal-indent-level))
761 (case . (+ ind pascal-case-indent)) 763 (case . (+ pascal--extra-indent pascal-case-indent))
762 (caseblock . ind) (cpp . 0) 764 (caseblock . pascal--extra-indent) (cpp . 0)
763 (declaration . (+ ind pascal-indent-level)) 765 (declaration . (+ pascal--extra-indent pascal-indent-level))
764 (paramlist . (pascal-indent-paramlist t)) 766 (paramlist . (pascal-indent-paramlist t))
765 (comment . (pascal-indent-comment)) 767 (comment . (pascal-indent-comment))
766 (defun . ind) (contexp . ind) 768 (defun . pascal--extra-indent) (contexp . pascal--extra-indent)
767 (unknown . ind) (string . 0) (progbeg . 0))) 769 (unknown . pascal--extra-indent) (string . 0) (progbeg . 0)))
768 770
769(defun pascal-indent-command () 771(defun pascal-indent-command ()
770 "Indent for special part of code." 772 "Indent for special part of code."
@@ -786,12 +788,11 @@ on the line which ends a function or procedure named NAME."
786 (if (looking-at "[ \t]+$") 788 (if (looking-at "[ \t]+$")
787 (skip-chars-forward " \t")))) 789 (skip-chars-forward " \t"))))
788 790
789(defvar ind) ;Used via `eval' in pascal-indent-alist.
790(defun pascal-indent-line () 791(defun pascal-indent-line ()
791 "Indent current line as a Pascal statement." 792 "Indent current line as a Pascal statement."
792 (let* ((indent-str (pascal-calculate-indent)) 793 (let* ((indent-str (pascal-calculate-indent))
793 (type (car indent-str)) 794 (type (car indent-str))
794 (ind (car (cdr indent-str)))) 795 (pascal--extra-indent (car (cdr indent-str))))
795 ;; Labels should not be indented. 796 ;; Labels should not be indented.
796 (if (and (looking-at "^[0-9a-zA-Z]+[ \t]*:[^=]") 797 (if (and (looking-at "^[0-9a-zA-Z]+[ \t]*:[^=]")
797 (not (eq type 'declaration))) 798 (not (eq type 'declaration)))
@@ -803,13 +804,13 @@ on the line which ends a function or procedure named NAME."
803 ()) 804 ())
804 (; Other things should have no extra indent 805 (; Other things should have no extra indent
805 (looking-at pascal-noindent-re) 806 (looking-at pascal-noindent-re)
806 (indent-to ind)) 807 (indent-to pascal--extra-indent))
807 (; Nested functions should be indented 808 (; Nested functions should be indented
808 (looking-at pascal-defun-re) 809 (looking-at pascal-defun-re)
809 (if (and pascal-indent-nested-functions 810 (if (and pascal-indent-nested-functions
810 (eq type 'defun)) 811 (eq type 'defun))
811 (indent-to (+ ind pascal-indent-level)) 812 (indent-to (+ pascal--extra-indent pascal-indent-level))
812 (indent-to ind))) 813 (indent-to pascal--extra-indent)))
813 (; But most lines are treated this way 814 (; But most lines are treated this way
814 (indent-to (eval (cdr (assoc type pascal-indent-alist)))) 815 (indent-to (eval (cdr (assoc type pascal-indent-alist))))
815 )))) 816 ))))
@@ -949,7 +950,7 @@ Do not count labels, case-statements or records."
949 (point-marker) 950 (point-marker)
950 (re-search-backward "\\<case\\>" nil t))) 951 (re-search-backward "\\<case\\>" nil t)))
951 (beg (point)) 952 (beg (point))
952 (ind 0)) 953 (pascal--extra-indent 0))
953 ;; Get right indent 954 ;; Get right indent
954 (while (< (point) end) 955 (while (< (point) end)
955 (if (re-search-forward 956 (if (re-search-forward
@@ -959,8 +960,8 @@ Do not count labels, case-statements or records."
959 (if (< (point) end) 960 (if (< (point) end)
960 (progn 961 (progn
961 (delete-horizontal-space) 962 (delete-horizontal-space)
962 (if (> (current-column) ind) 963 (if (> (current-column) pascal--extra-indent)
963 (setq ind (current-column))) 964 (setq pascal--extra-indent (current-column)))
964 (pascal-end-of-statement)))) 965 (pascal-end-of-statement))))
965 (goto-char beg) 966 (goto-char beg)
966 ;; Indent all case statements 967 ;; Indent all case statements
@@ -969,7 +970,7 @@ Do not count labels, case-statements or records."
969 "^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:" 970 "^[ \t]*[^][ \t,\\.:]+[ \t]*\\(,[ \t]*[^ \t,:]+[ \t]*\\)*:"
970 (marker-position end) 'move) 971 (marker-position end) 'move)
971 (forward-char -1)) 972 (forward-char -1))
972 (indent-to (1+ ind)) 973 (indent-to (1+ pascal--extra-indent))
973 (if (/= (following-char) ?:) 974 (if (/= (following-char) ?:)
974 () 975 ()
975 (forward-char 1) 976 (forward-char 1)
@@ -1017,7 +1018,7 @@ indent of the current line in parameterlist."
1017 (max (progn (pascal-declaration-end) 1018 (max (progn (pascal-declaration-end)
1018 (point)) 1019 (point))
1019 pos)))) 1020 pos))))
1020 ind) 1021 pascal--extra-indent)
1021 1022
1022 (goto-char stpos) 1023 (goto-char stpos)
1023 ;; Indent lines in record block 1024 ;; Indent lines in record block
@@ -1031,13 +1032,13 @@ indent of the current line in parameterlist."
1031 (forward-line 1))) 1032 (forward-line 1)))
1032 1033
1033 ;; Do lineup 1034 ;; Do lineup
1034 (setq ind (pascal-get-lineup-indent stpos edpos lineup)) 1035 (setq pascal--extra-indent (pascal-get-lineup-indent stpos edpos lineup))
1035 (goto-char stpos) 1036 (goto-char stpos)
1036 (while (and (<= (point) edpos) (not (eobp))) 1037 (while (and (<= (point) edpos) (not (eobp)))
1037 (if (search-forward lineup (point-at-eol) 'move) 1038 (if (search-forward lineup (point-at-eol) 'move)
1038 (forward-char -1)) 1039 (forward-char -1))
1039 (delete-horizontal-space) 1040 (delete-horizontal-space)
1040 (indent-to ind) 1041 (indent-to pascal--extra-indent)
1041 (if (not (looking-at lineup)) 1042 (if (not (looking-at lineup))
1042 (forward-line 1) ; No more indent if there is no : or = 1043 (forward-line 1) ; No more indent if there is no : or =
1043 (forward-char 1) 1044 (forward-char 1)
@@ -1056,7 +1057,7 @@ indent of the current line in parameterlist."
1056;from b to e nicely. The lineup string is str." 1057;from b to e nicely. The lineup string is str."
1057(defun pascal-get-lineup-indent (b e str) 1058(defun pascal-get-lineup-indent (b e str)
1058 (save-excursion 1059 (save-excursion
1059 (let ((ind 0) 1060 (let ((pascal--extra-indent 0)
1060 (reg (concat str "\\|\\(\\<record\\>\\)\\|" pascal-defun-re))) 1061 (reg (concat str "\\|\\(\\<record\\>\\)\\|" pascal-defun-re)))
1061 (goto-char b) 1062 (goto-char b)
1062 ;; Get rightmost position 1063 ;; Get rightmost position
@@ -1071,14 +1072,14 @@ indent of the current line in parameterlist."
1071 (t 1072 (t
1072 (goto-char (match-beginning 0)) 1073 (goto-char (match-beginning 0))
1073 (skip-chars-backward " \t") 1074 (skip-chars-backward " \t")
1074 (if (> (current-column) ind) 1075 (if (> (current-column) pascal--extra-indent)
1075 (setq ind (current-column))) 1076 (setq pascal--extra-indent (current-column)))
1076 (goto-char (match-end 0)) 1077 (goto-char (match-end 0))
1077 (end-of-line) 1078 (end-of-line)
1078 )))) 1079 ))))
1079 ;; In case no lineup was found 1080 ;; In case no lineup was found
1080 (if (> ind 0) 1081 (if (> pascal--extra-indent 0)
1081 (1+ ind) 1082 (1+ pascal--extra-indent)
1082 ;; No lineup-string found 1083 ;; No lineup-string found
1083 (goto-char b) 1084 (goto-char b)
1084 (end-of-line) 1085 (end-of-line)
@@ -1353,21 +1354,21 @@ The default is a name found in the buffer around point."
1353 (default (if (pascal-comp-defun default nil 'lambda) 1354 (default (if (pascal-comp-defun default nil 'lambda)
1354 default "")) 1355 default ""))
1355 (label 1356 (label
1356 ;; Do completion with default 1357 ;; Do completion with default.
1357 (completing-read (if (not (string= default "")) 1358 (completing-read (if (not (string= default ""))
1358 (concat "Label (default " default "): ") 1359 (concat "Label (default " default "): ")
1359 "Label: ") 1360 "Label: ")
1360 ;; Complete with the defuns found in the 1361 ;; Complete with the defuns found in the
1361 ;; current-buffer. 1362 ;; current-buffer.
1362 (lexical-let ((buf (current-buffer))) 1363 (let ((buf (current-buffer)))
1363 (lambda (s p a) 1364 (lambda (s p a)
1364 (with-current-buffer buf 1365 (with-current-buffer buf
1365 (pascal-comp-defun s p a)))) 1366 (pascal-comp-defun s p a))))
1366 nil t ""))) 1367 nil t "")))
1367 ;; If there was no response on prompt, use default value 1368 ;; If there was no response on prompt, use default value.
1368 (if (string= label "") 1369 (if (string= label "")
1369 (setq label default)) 1370 (setq label default))
1370 ;; Goto right place in buffer if label is not an empty string 1371 ;; Goto right place in buffer if label is not an empty string.
1371 (or (string= label "") 1372 (or (string= label "")
1372 (progn 1373 (progn
1373 (goto-char (point-min)) 1374 (goto-char (point-min))
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index 74c8c31b425..16d85cb2d79 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -295,7 +295,7 @@
295 295
296 296
297(defgroup prolog nil 297(defgroup prolog nil
298 "Major modes for editing and running Prolog and Mercury files." 298 "Editing and running Prolog and Mercury files."
299 :group 'languages) 299 :group 'languages)
300 300
301(defgroup prolog-faces nil 301(defgroup prolog-faces nil
@@ -833,18 +833,116 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24."
833 ) 833 )
834 table)) 834 table))
835(defvar prolog-mode-abbrev-table nil) 835(defvar prolog-mode-abbrev-table nil)
836(defvar prolog-upper-case-string "" 836
837 "A string containing all upper case characters. 837(if (eval-when-compile
838Set by prolog-build-case-strings.") 838 (and (string-match "[[:upper:]]" "A")
839(defvar prolog-lower-case-string "" 839 (with-temp-buffer
840 "A string containing all lower case characters. 840 (insert "A") (skip-chars-backward "[:upper:]") (bolp))))
841Set by prolog-build-case-strings.") 841 (progn
842 842 (defconst prolog-upper-case-string "[:upper:]"
843(defvar prolog-atom-char-regexp "" 843 "A string containing a char-range matching all upper case characters.")
844 "Set by prolog-set-atom-regexps.") 844 (defconst prolog-lower-case-string "[:lower:]"
845;; "Regexp specifying characters which constitute atoms without quoting.") 845 "A string containing a char-range matching all lower case characters."))
846(defvar prolog-atom-regexp "" 846
847 "Set by prolog-set-atom-regexps.") 847 ;; GNU Emacs compatibility: GNU Emacs does not differentiate between
848 ;; ints and chars, or at least these two are interchangeable.
849 (defalias 'prolog-int-to-char
850 (if (fboundp 'int-to-char) #'int-to-char #'identity))
851
852 (defalias 'prolog-char-to-int
853 (if (fboundp 'char-to-int) #'char-to-int #'identity))
854
855 (defun prolog-ints-intervals (ints)
856 "Return a list of intervals (from . to) covering INTS."
857 (when ints
858 (setq ints (sort ints '<))
859 (let ((prev (car ints))
860 (interval-start (car ints))
861 intervals)
862 (while ints
863 (let ((next (car ints)))
864 (when (> next (1+ prev)) ; start of new interval
865 (setq intervals (cons (cons interval-start prev) intervals))
866 (setq interval-start next))
867 (setq prev next)
868 (setq ints (cdr ints))))
869 (setq intervals (cons (cons interval-start prev) intervals))
870 (reverse intervals))))
871
872 (defun prolog-dash-letters (string)
873 "Return a condensed regexp covering all letters in STRING."
874 (let ((intervals (prolog-ints-intervals (mapcar #'prolog-char-to-int
875 (string-to-list string))))
876 codes)
877 (while intervals
878 (let* ((i (car intervals))
879 (from (car i))
880 (to (cdr i))
881 (c (cond ((= from to) `(,from))
882 ((= (1+ from) to) `(,from ,to))
883 (t `(,from ?- ,to)))))
884 (setq codes (cons c codes)))
885 (setq intervals (cdr intervals)))
886 (apply 'concat (reverse codes))))
887
888 (let ((up_string "")
889 (low_string ""))
890 ;; Use `map-char-table' if it is defined. Otherwise enumerate all
891 ;; numbers between 0 and 255. `map-char-table' is probably safer.
892 ;;
893 ;; `map-char-table' causes problems under Emacs 23.0.0.1, the
894 ;; while loop seems to do its job well (Ryszard Szopa)
895 ;;
896 ;;(if (and (not (featurep 'xemacs))
897 ;; (fboundp 'map-char-table))
898 ;; (map-char-table
899 ;; (lambda (key value)
900 ;; (cond
901 ;; ((and
902 ;; (eq (prolog-int-to-char key) (downcase key))
903 ;; (eq (prolog-int-to-char key) (upcase key)))
904 ;; ;; Do nothing if upper and lower case are the same
905 ;; )
906 ;; ((eq (prolog-int-to-char key) (downcase key))
907 ;; ;; The char is lower case
908 ;; (setq low_string (format "%s%c" low_string key)))
909 ;; ((eq (prolog-int-to-char key) (upcase key))
910 ;; ;; The char is upper case
911 ;; (setq up_string (format "%s%c" up_string key)))
912 ;; ))
913 ;; (current-case-table))
914 ;; `map-char-table' was undefined.
915 (let ((key 0))
916 (while (< key 256)
917 (cond
918 ((and
919 (eq (prolog-int-to-char key) (downcase key))
920 (eq (prolog-int-to-char key) (upcase key)))
921 ;; Do nothing if upper and lower case are the same
922 )
923 ((eq (prolog-int-to-char key) (downcase key))
924 ;; The char is lower case
925 (setq low_string (format "%s%c" low_string key)))
926 ((eq (prolog-int-to-char key) (upcase key))
927 ;; The char is upper case
928 (setq up_string (format "%s%c" up_string key)))
929 )
930 (setq key (1+ key))))
931 ;; )
932 ;; The strings are single-byte strings.
933 (defconst prolog-upper-case-string (prolog-dash-letters up_string)
934 "A string containing a char-range matching all upper case characters.")
935 (defconst prolog-lower-case-string (prolog-dash-letters low_string)
936 "A string containing a char-range matching all lower case characters.")
937 ))
938
939(defconst prolog-atom-char-regexp
940 (if (string-match "[[:alnum:]]" "0")
941 "[[:alnum:]_$]"
942 (format "[%s%s0-9_$]" prolog-lower-case-string prolog-upper-case-string))
943 "Regexp specifying characters which constitute atoms without quoting.")
944(defconst prolog-atom-regexp
945 (format "[%s$]%s*" prolog-lower-case-string prolog-atom-char-regexp))
848 946
849(defconst prolog-left-paren "[[({]" ;FIXME: Why not \\s(? 947(defconst prolog-left-paren "[[({]" ;FIXME: Why not \\s(?
850 "The characters used as left parentheses for the indentation code.") 948 "The characters used as left parentheses for the indentation code.")
@@ -887,6 +985,96 @@ Set by prolog-build-case-strings.")
887 '(("dcg" . "-->") ("rule" . ":-") ("simplification" . "<=>") 985 '(("dcg" . "-->") ("rule" . ":-") ("simplification" . "<=>")
888 ("propagation" . "==>"))))) 986 ("propagation" . "==>")))))
889 987
988;; SMIE support
989
990(require 'smie)
991
992(defvar prolog-use-smie t)
993
994(defun prolog-smie-forward-token ()
995 ;; FIXME: Add support for 0'<char>, if needed after adding it to
996 ;; syntax-propertize-functions.
997 (forward-comment (point-max))
998 (buffer-substring-no-properties
999 (point)
1000 (progn (cond
1001 ((looking-at "[!;]") (forward-char 1))
1002 ((not (zerop (skip-chars-forward "#&*+-./:<=>?@\\^`~"))))
1003 ((not (zerop (skip-syntax-forward "w_'"))))
1004 ;; In case of non-ASCII punctuation.
1005 ((not (zerop (skip-syntax-forward ".")))))
1006 (point))))
1007
1008(defun prolog-smie-backward-token ()
1009 ;; FIXME: Add support for 0'<char>, if needed after adding it to
1010 ;; syntax-propertize-functions.
1011 (forward-comment (- (point-max)))
1012 (buffer-substring-no-properties
1013 (point)
1014 (progn (cond
1015 ((memq (char-before) '(?! ?\;)) (forward-char -1))
1016 ((not (zerop (skip-chars-backward "#&*+-./:<=>?@\\^`~"))))
1017 ((not (zerop (skip-syntax-backward "w_'"))))
1018 ;; In case of non-ASCII punctuation.
1019 ((not (zerop (skip-syntax-backward ".")))))
1020 (point))))
1021
1022(defconst prolog-smie-grammar
1023 ;; Rather than construct the operator levels table from the BNF,
1024 ;; we directly provide the operator precedences from GNU Prolog's
1025 ;; manual (7.14.10 op/3). The only problem is that GNU Prolog's
1026 ;; manual uses precedence levels in the opposite sense (higher
1027 ;; numbers bind less tightly) than SMIE, so we use negative numbers.
1028 '(("." -10000 -10000)
1029 (":-" -1200 -1200)
1030 ("-->" -1200 -1200)
1031 (";" -1100 -1100)
1032 ("->" -1050 -1050)
1033 ("," -1000 -1000)
1034 ("\\+" -900 -900)
1035 ("=" -700 -700)
1036 ("\\=" -700 -700)
1037 ("=.." -700 -700)
1038 ("==" -700 -700)
1039 ("\\==" -700 -700)
1040 ("@<" -700 -700)
1041 ("@=<" -700 -700)
1042 ("@>" -700 -700)
1043 ("@>=" -700 -700)
1044 ("is" -700 -700)
1045 ("=:=" -700 -700)
1046 ("=\\=" -700 -700)
1047 ("<" -700 -700)
1048 ("=<" -700 -700)
1049 (">" -700 -700)
1050 (">=" -700 -700)
1051 (":" -600 -600)
1052 ("+" -500 -500)
1053 ("-" -500 -500)
1054 ("/\\" -500 -500)
1055 ("\\/" -500 -500)
1056 ("*" -400 -400)
1057 ("/" -400 -400)
1058 ("//" -400 -400)
1059 ("rem" -400 -400)
1060 ("mod" -400 -400)
1061 ("<<" -400 -400)
1062 (">>" -400 -400)
1063 ("**" -200 -200)
1064 ("^" -200 -200)
1065 ;; Prefix
1066 ;; ("+" 200 200)
1067 ;; ("-" 200 200)
1068 ;; ("\\" 200 200)
1069 (:smie-closer-alist (t . "."))
1070 )
1071 "Precedence levels of infix operators.")
1072
1073(defun prolog-smie-rules (kind token)
1074 (pcase (cons kind token)
1075 (`(:elem . basic) prolog-indent-width)
1076 (`(:after . ".") '(column . 0)) ;; To work around smie-closer-alist.
1077 (`(:after . ,(or `":-" `"->" `"-->")) prolog-indent-width)))
890 1078
891 1079
892;;------------------------------------------------------------------- 1080;;-------------------------------------------------------------------
@@ -959,7 +1147,6 @@ VERSION is of the format (Major . Minor)"
959 (set (make-local-variable 'paragraph-separate) paragraph-start) 1147 (set (make-local-variable 'paragraph-separate) paragraph-start)
960 (set (make-local-variable 'paragraph-ignore-fill-prefix) t) 1148 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
961 (set (make-local-variable 'normal-auto-fill-function) 'prolog-do-auto-fill) 1149 (set (make-local-variable 'normal-auto-fill-function) 'prolog-do-auto-fill)
962 (set (make-local-variable 'indent-line-function) 'prolog-indent-line)
963 (set (make-local-variable 'comment-start) "%") 1150 (set (make-local-variable 'comment-start) "%")
964 (set (make-local-variable 'comment-end) "") 1151 (set (make-local-variable 'comment-end) "")
965 (set (make-local-variable 'comment-add) 1) 1152 (set (make-local-variable 'comment-add) 1)
@@ -968,7 +1155,6 @@ VERSION is of the format (Major . Minor)"
968 ;; inside quoted atoms or strings 1155 ;; inside quoted atoms or strings
969 (format "^\\(\\(%s\\|%s\\|[^\n\'\"%%]\\)*\\)\\(/\\*+ *\\|%%+ *\\)" 1156 (format "^\\(\\(%s\\|%s\\|[^\n\'\"%%]\\)*\\)\\(/\\*+ *\\|%%+ *\\)"
970 prolog-quoted-atom-regexp prolog-string-regexp)) 1157 prolog-quoted-atom-regexp prolog-string-regexp))
971 (set (make-local-variable 'comment-indent-function) 'prolog-comment-indent)
972 (set (make-local-variable 'parens-require-spaces) nil) 1158 (set (make-local-variable 'parens-require-spaces) nil)
973 ;; Initialize Prolog system specific variables 1159 ;; Initialize Prolog system specific variables
974 (dolist (var '(prolog-keywords prolog-types prolog-mode-specificators 1160 (dolist (var '(prolog-keywords prolog-types prolog-mode-specificators
@@ -984,6 +1170,13 @@ VERSION is of the format (Major . Minor)"
984 '(prolog-font-lock-keywords nil nil ((?_ . "w")))) 1170 '(prolog-font-lock-keywords nil nil ((?_ . "w"))))
985 (set (make-local-variable 'syntax-propertize-function) 1171 (set (make-local-variable 'syntax-propertize-function)
986 prolog-syntax-propertize-function) 1172 prolog-syntax-propertize-function)
1173
1174 (if prolog-use-smie
1175 ;; Setup SMIE.
1176 (smie-setup prolog-smie-grammar #'prolog-smie-rules
1177 :forward-token #'prolog-smie-forward-token
1178 :backward-token #'prolog-smie-backward-token)
1179 (set (make-local-variable 'indent-line-function) 'prolog-indent-line))
987 ) 1180 )
988 1181
989(defun prolog-mode-keybindings-common (map) 1182(defun prolog-mode-keybindings-common (map)
@@ -1096,11 +1289,9 @@ if that value is non-nil."
1096 ((eq prolog-system 'gnu) "[GNU]") 1289 ((eq prolog-system 'gnu) "[GNU]")
1097 (t "")))) 1290 (t ""))))
1098 (prolog-mode-variables) 1291 (prolog-mode-variables)
1099 (prolog-build-case-strings)
1100 (prolog-set-atom-regexps)
1101 (dolist (ar prolog-align-rules) (add-to-list 'align-rules-list ar)) 1292 (dolist (ar prolog-align-rules) (add-to-list 'align-rules-list ar))
1102 1293
1103 ;; imenu entry moved to the appropriate hook for consistency 1294 ;; `imenu' entry moved to the appropriate hook for consistency.
1104 1295
1105 ;; Load SICStus debugger if suitable 1296 ;; Load SICStus debugger if suitable
1106 (if (and (eq prolog-system 'sicstus) 1297 (if (and (eq prolog-system 'sicstus)
@@ -1614,7 +1805,8 @@ For use with the `compilation-parse-errors-function' variable."
1614 limit t) 1805 limit t)
1615 (setq filepath (match-string 2))) 1806 (setq filepath (match-string 2)))
1616 1807
1617 ;; ###### Does this work with SICStus under Windows (i.e. backslashes and stuff?) 1808 ;; ###### Does this work with SICStus under Windows
1809 ;; (i.e. backslashes and stuff?)
1618 (if (string-match "\\(.*/\\)\\([^/]*\\)$" filepath) 1810 (if (string-match "\\(.*/\\)\\([^/]*\\)$" filepath)
1619 (progn 1811 (progn
1620 (setq dir (match-string 1 filepath)) 1812 (setq dir (match-string 1 filepath))
@@ -1838,7 +2030,8 @@ Argument BOUND is a buffer position limiting searching."
1838 (defface prolog-builtin-face 2030 (defface prolog-builtin-face
1839 '((((class color) (background light)) (:foreground "Purple")) 2031 '((((class color) (background light)) (:foreground "Purple"))
1840 (((class color) (background dark)) (:foreground "Cyan")) 2032 (((class color) (background dark)) (:foreground "Cyan"))
1841 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) 2033 (((class grayscale) (background light))
2034 :foreground "LightGray" :bold t)
1842 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) 2035 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
1843 (t (:bold t))) 2036 (t (:bold t)))
1844 "Face name to use for compiler warnings." 2037 "Face name to use for compiler warnings."
@@ -2093,20 +2286,6 @@ rigidly along with this one (not yet)."
2093 (prolog-insert-spaces-after-paren)) 2286 (prolog-insert-spaces-after-paren))
2094 )) 2287 ))
2095 2288
2096(defun prolog-comment-indent ()
2097 "Compute prolog comment indentation."
2098 ;; FIXME: Only difference with default behavior is that %%% is not
2099 ;; flushed to column 0 but just left where the user put it.
2100 (cond ((looking-at "%%%") (prolog-indentation-level-of-line))
2101 ((looking-at "%%") (prolog-indent-level))
2102 (t
2103 (save-excursion
2104 (skip-chars-backward " \t")
2105 ;; Insert one space at least, except at left margin.
2106 (max (+ (current-column) (if (bolp) 0 1))
2107 comment-column)))
2108 ))
2109
2110(defun prolog-indent-level () 2289(defun prolog-indent-level ()
2111 "Compute prolog indentation level." 2290 "Compute prolog indentation level."
2112 (save-excursion 2291 (save-excursion
@@ -3200,7 +3379,8 @@ When called with prefix argument ARG, disable zipping instead."
3200 (save-excursion 3379 (save-excursion
3201 (let ((state (prolog-clause-info)) 3380 (let ((state (prolog-clause-info))
3202 (object (prolog-in-object))) 3381 (object (prolog-in-object)))
3203 (if (or (equal (nth 0 state) "") (equal (prolog-in-string-or-comment) 'cmt)) 3382 (if (or (equal (nth 0 state) "")
3383 (equal (prolog-in-string-or-comment) 'cmt))
3204 nil 3384 nil
3205 (if (and (eq prolog-system 'sicstus) 3385 (if (and (eq prolog-system 'sicstus)
3206 object) 3386 object)
@@ -3229,6 +3409,7 @@ STRING should be given if the last search was by `string-match' on STRING."
3229 3409
3230(defun prolog-pred-start () 3410(defun prolog-pred-start ()
3231 "Return the starting point of the first clause of the current predicate." 3411 "Return the starting point of the first clause of the current predicate."
3412 ;; FIXME: Use SMIE.
3232 (save-excursion 3413 (save-excursion
3233 (goto-char (prolog-clause-start)) 3414 (goto-char (prolog-clause-start))
3234 ;; Find first clause, unless it was a directive 3415 ;; Find first clause, unless it was a directive
@@ -3261,8 +3442,9 @@ STRING should be given if the last search was by `string-match' on STRING."
3261 3442
3262(defun prolog-pred-end () 3443(defun prolog-pred-end ()
3263 "Return the position at the end of the last clause of the current predicate." 3444 "Return the position at the end of the last clause of the current predicate."
3445 ;; FIXME: Use SMIE.
3264 (save-excursion 3446 (save-excursion
3265 (goto-char (prolog-clause-end)) ; if we are before the first predicate 3447 (goto-char (prolog-clause-end)) ; If we are before the first predicate.
3266 (goto-char (prolog-clause-start)) 3448 (goto-char (prolog-clause-start))
3267 (let* ((pinfo (prolog-clause-info)) 3449 (let* ((pinfo (prolog-clause-info))
3268 (predname (nth 0 pinfo)) 3450 (predname (nth 0 pinfo))
@@ -3517,6 +3699,7 @@ If already at the end of clause, move to next clause."
3517(defun prolog-beginning-of-predicate () 3699(defun prolog-beginning-of-predicate ()
3518 "Go to the nearest beginning of predicate before current point. 3700 "Go to the nearest beginning of predicate before current point.
3519Return the final point or nil if no such a beginning was found." 3701Return the final point or nil if no such a beginning was found."
3702 ;; FIXME: Hook into beginning-of-defun.
3520 (interactive) 3703 (interactive)
3521 (let ((op (point)) 3704 (let ((op (point))
3522 (pos (prolog-pred-start))) 3705 (pos (prolog-pred-start)))
@@ -3536,6 +3719,7 @@ Return the final point or nil if no such a beginning was found."
3536 3719
3537(defun prolog-end-of-predicate () 3720(defun prolog-end-of-predicate ()
3538 "Go to the end of the current predicate." 3721 "Go to the end of the current predicate."
3722 ;; FIXME: Hook into end-of-defun.
3539 (interactive) 3723 (interactive)
3540 (let ((op (point))) 3724 (let ((op (point)))
3541 (goto-char (prolog-pred-end)) 3725 (goto-char (prolog-pred-end))
@@ -3657,7 +3841,7 @@ a new comment is created."
3657 "Delete preceding character or whitespace. 3841 "Delete preceding character or whitespace.
3658If `prolog-hungry-delete-key-flag' is non-nil, then all preceding whitespace is 3842If `prolog-hungry-delete-key-flag' is non-nil, then all preceding whitespace is
3659consumed. If however an ARG is supplied, or `prolog-hungry-delete-key-flag' is 3843consumed. If however an ARG is supplied, or `prolog-hungry-delete-key-flag' is
3660nil, or point is inside a literal then the function in the variable 3844nil, or point is inside a literal then the function
3661`backward-delete-char' is called." 3845`backward-delete-char' is called."
3662 (interactive "P") 3846 (interactive "P")
3663 (if (or (not prolog-hungry-delete-key-flag) 3847 (if (or (not prolog-hungry-delete-key-flag)
@@ -3677,6 +3861,7 @@ nil, or point is inside a literal then the function in the variable
3677(defun prolog-electric-if-then-else (arg) 3861(defun prolog-electric-if-then-else (arg)
3678 "If `prolog-electric-if-then-else-flag' is non-nil, indent if-then-else constructs. 3862 "If `prolog-electric-if-then-else-flag' is non-nil, indent if-then-else constructs.
3679Bound to the >, ; and ( keys." 3863Bound to the >, ; and ( keys."
3864 ;; FIXME: Use post-self-insert-hook or electric-indent-mode.
3680 (interactive "P") 3865 (interactive "P")
3681 (self-insert-command (prefix-numeric-value arg)) 3866 (self-insert-command (prefix-numeric-value arg))
3682 (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren))) 3867 (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren)))
@@ -3686,6 +3871,7 @@ Bound to the >, ; and ( keys."
3686That is, insert space (if appropriate), `:-' and newline if colon is pressed 3871That is, insert space (if appropriate), `:-' and newline if colon is pressed
3687at the end of a line that starts in the first column (i.e., clause 3872at the end of a line that starts in the first column (i.e., clause
3688heads)." 3873heads)."
3874 ;; FIXME: Use post-self-insert-hook.
3689 (interactive "P") 3875 (interactive "P")
3690 (if (and prolog-electric-colon-flag 3876 (if (and prolog-electric-colon-flag
3691 (null arg) 3877 (null arg)
@@ -3696,7 +3882,7 @@ heads)."
3696 (unless (save-excursion (backward-char 1) (looking-at "\\s ")) 3882 (unless (save-excursion (backward-char 1) (looking-at "\\s "))
3697 (insert " ")) 3883 (insert " "))
3698 (insert ":-\n") 3884 (insert ":-\n")
3699 (prolog-indent-line)) 3885 (indent-according-to-mode))
3700 (self-insert-command (prefix-numeric-value arg)))) 3886 (self-insert-command (prefix-numeric-value arg))))
3701 3887
3702(defun prolog-electric-dash (arg) 3888(defun prolog-electric-dash (arg)
@@ -3704,6 +3890,7 @@ heads)."
3704that is, insert space (if appropriate), `-->' and newline if dash is pressed 3890that is, insert space (if appropriate), `-->' and newline if dash is pressed
3705at the end of a line that starts in the first column (i.e., DCG 3891at the end of a line that starts in the first column (i.e., DCG
3706heads)." 3892heads)."
3893 ;; FIXME: Use post-self-insert-hook.
3707 (interactive "P") 3894 (interactive "P")
3708 (if (and prolog-electric-dash-flag 3895 (if (and prolog-electric-dash-flag
3709 (null arg) 3896 (null arg)
@@ -3714,7 +3901,7 @@ heads)."
3714 (unless (save-excursion (backward-char 1) (looking-at "\\s ")) 3901 (unless (save-excursion (backward-char 1) (looking-at "\\s "))
3715 (insert " ")) 3902 (insert " "))
3716 (insert "-->\n") 3903 (insert "-->\n")
3717 (prolog-indent-line)) 3904 (indent-according-to-mode))
3718 (self-insert-command (prefix-numeric-value arg)))) 3905 (self-insert-command (prefix-numeric-value arg))))
3719 3906
3720(defun prolog-electric-dot (arg) 3907(defun prolog-electric-dot (arg)
@@ -3729,6 +3916,7 @@ When invoked at the beginning of line, insert a head of a new clause
3729of the current predicate. 3916of the current predicate.
3730 3917
3731When called with prefix argument ARG, insert just dot." 3918When called with prefix argument ARG, insert just dot."
3919 ;; FIXME: Use post-self-insert-hook.
3732 (interactive "P") 3920 (interactive "P")
3733 ;; Check for situations when the electricity should not be active 3921 ;; Check for situations when the electricity should not be active
3734 (if (or (not prolog-electric-dot-flag) 3922 (if (or (not prolog-electric-dot-flag)
@@ -3788,6 +3976,7 @@ If `prolog-electric-underscore-flag' is non-nil and the point is
3788on a variable then replace the variable with underscore and skip 3976on a variable then replace the variable with underscore and skip
3789the following comma and whitespace, if any. 3977the following comma and whitespace, if any.
3790If the point is not on a variable then insert underscore." 3978If the point is not on a variable then insert underscore."
3979 ;; FIXME: Use post-self-insert-hook.
3791 (interactive) 3980 (interactive)
3792 (if prolog-electric-underscore-flag 3981 (if prolog-electric-underscore-flag
3793 (let (;start 3982 (let (;start
@@ -3862,144 +4051,36 @@ PREFIX is the prefix of the search regexp."
3862 (backward-char))) 4051 (backward-char)))
3863 ))) 4052 )))
3864 4053
4054;;(defun prolog-regexp-dash-continuous-chars (chars)
4055;; (let ((ints (mapcar #'prolog-char-to-int (string-to-list chars)))
4056;; (beg 0)
4057;; (end 0))
4058;; (if (null ints)
4059;; chars
4060;; (while (and (< (+ beg 1) (length chars))
4061;; (not (or (= (+ (nth beg ints) 1) (nth (+ beg 1) ints))
4062;; (= (nth beg ints) (nth (+ beg 1) ints)))))
4063;; (setq beg (+ beg 1)))
4064;; (setq beg (+ beg 1)
4065;; end beg)
4066;; (while (and (< (+ end 1) (length chars))
4067;; (or (= (+ (nth end ints) 1) (nth (+ end 1) ints))
4068;; (= (nth end ints) (nth (+ end 1) ints))))
4069;; (setq end (+ end 1)))
4070;; (if (equal (substring chars end) "")
4071;; (substring chars 0 beg)
4072;; (concat (substring chars 0 beg) "-"
4073;; (prolog-regexp-dash-continuous-chars (substring chars end))))
4074;; )))
4075
4076;;(defun prolog-condense-character-sets (regexp)
4077;; "Condense adjacent characters in character sets of REGEXP."
4078;; (let ((next -1))
4079;; (while (setq next (string-match "\\[\\(.*?\\)\\]" regexp (1+ next)))
4080;; (setq regexp (replace-match (prolog-dash-letters (match-string 1 regexp))
4081;; t t regexp 1))))
4082;; regexp)
3865 4083
3866(defun prolog-set-atom-regexps ()
3867 "Set the `prolog-atom-char-regexp' and `prolog-atom-regexp' variables.
3868Must be called after `prolog-build-case-strings'."
3869 (setq prolog-atom-char-regexp
3870 (format "[%s%s0-9_$]"
3871 ;; FIXME: why not a-zA-Z?
3872 prolog-lower-case-string
3873 prolog-upper-case-string))
3874 (setq prolog-atom-regexp
3875 (format "[%s$]%s*"
3876 prolog-lower-case-string
3877 prolog-atom-char-regexp))
3878 )
3879
3880(defun prolog-build-case-strings ()
3881 "Set `prolog-upper-case-string' and `prolog-lower-case-string'.
3882Uses the current case-table for extracting the relevant information."
3883 (let ((up_string "")
3884 (low_string ""))
3885 ;; Use `map-char-table' if it is defined. Otherwise enumerate all
3886 ;; numbers between 0 and 255. `map-char-table' is probably safer.
3887 ;;
3888 ;; `map-char-table' causes problems under Emacs 23.0.0.1, the
3889 ;; while loop seems to do its job well (Ryszard Szopa)
3890 ;;
3891 ;;(if (and (not (featurep 'xemacs))
3892 ;; (fboundp 'map-char-table))
3893 ;; (map-char-table
3894 ;; (lambda (key value)
3895 ;; (cond
3896 ;; ((and
3897 ;; (eq (prolog-int-to-char key) (downcase key))
3898 ;; (eq (prolog-int-to-char key) (upcase key)))
3899 ;; ;; Do nothing if upper and lower case are the same
3900 ;; )
3901 ;; ((eq (prolog-int-to-char key) (downcase key))
3902 ;; ;; The char is lower case
3903 ;; (setq low_string (format "%s%c" low_string key)))
3904 ;; ((eq (prolog-int-to-char key) (upcase key))
3905 ;; ;; The char is upper case
3906 ;; (setq up_string (format "%s%c" up_string key)))
3907 ;; ))
3908 ;; (current-case-table))
3909 ;; `map-char-table' was undefined.
3910 (let ((key 0))
3911 (while (< key 256)
3912 (cond
3913 ((and
3914 (eq (prolog-int-to-char key) (downcase key))
3915 (eq (prolog-int-to-char key) (upcase key)))
3916 ;; Do nothing if upper and lower case are the same
3917 )
3918 ((eq (prolog-int-to-char key) (downcase key))
3919 ;; The char is lower case
3920 (setq low_string (format "%s%c" low_string key)))
3921 ((eq (prolog-int-to-char key) (upcase key))
3922 ;; The char is upper case
3923 (setq up_string (format "%s%c" up_string key)))
3924 )
3925 (setq key (1+ key))))
3926 ;; )
3927 ;; The strings are single-byte strings
3928 (setq prolog-upper-case-string (prolog-dash-letters up_string))
3929 (setq prolog-lower-case-string (prolog-dash-letters low_string))
3930 ))
3931
3932;(defun prolog-regexp-dash-continuous-chars (chars)
3933; (let ((ints (mapcar #'prolog-char-to-int (string-to-list chars)))
3934; (beg 0)
3935; (end 0))
3936; (if (null ints)
3937; chars
3938; (while (and (< (+ beg 1) (length chars))
3939; (not (or (= (+ (nth beg ints) 1) (nth (+ beg 1) ints))
3940; (= (nth beg ints) (nth (+ beg 1) ints)))))
3941; (setq beg (+ beg 1)))
3942; (setq beg (+ beg 1)
3943; end beg)
3944; (while (and (< (+ end 1) (length chars))
3945; (or (= (+ (nth end ints) 1) (nth (+ end 1) ints))
3946; (= (nth end ints) (nth (+ end 1) ints))))
3947; (setq end (+ end 1)))
3948; (if (equal (substring chars end) "")
3949; (substring chars 0 beg)
3950; (concat (substring chars 0 beg) "-"
3951; (prolog-regexp-dash-continuous-chars (substring chars end))))
3952; )))
3953
3954(defun prolog-ints-intervals (ints)
3955 "Return a list of intervals (from . to) covering INTS."
3956 (when ints
3957 (setq ints (sort ints '<))
3958 (let ((prev (car ints))
3959 (interval-start (car ints))
3960 intervals)
3961 (while ints
3962 (let ((next (car ints)))
3963 (when (> next (1+ prev)) ; start of new interval
3964 (setq intervals (cons (cons interval-start prev) intervals))
3965 (setq interval-start next))
3966 (setq prev next)
3967 (setq ints (cdr ints))))
3968 (setq intervals (cons (cons interval-start prev) intervals))
3969 (reverse intervals))))
3970
3971(defun prolog-dash-letters (string)
3972 "Return a condensed regexp covering all letters in STRING."
3973 (let ((intervals (prolog-ints-intervals (mapcar #'prolog-char-to-int
3974 (string-to-list string))))
3975 codes)
3976 (while intervals
3977 (let* ((i (car intervals))
3978 (from (car i))
3979 (to (cdr i))
3980 (c (cond ((= from to) `(,from))
3981 ((= (1+ from) to) `(,from ,to))
3982 (t `(,from ?- ,to)))))
3983 (setq codes (cons c codes)))
3984 (setq intervals (cdr intervals)))
3985 (apply 'concat (reverse codes))))
3986
3987;(defun prolog-condense-character-sets (regexp)
3988; "Condense adjacent characters in character sets of REGEXP."
3989; (let ((next -1))
3990; (while (setq next (string-match "\\[\\(.*?\\)\\]" regexp (1+ next)))
3991; (setq regexp (replace-match (prolog-dash-letters (match-string 1 regexp))
3992; t t regexp 1))))
3993; regexp)
3994
3995;; GNU Emacs compatibility: GNU Emacs does not differentiate between
3996;; ints and chars, or at least these two are interchangeable.
3997(defalias 'prolog-int-to-char
3998 (if (fboundp 'int-to-char) #'int-to-char #'identity))
3999
4000(defalias 'prolog-char-to-int
4001 (if (fboundp 'char-to-int) #'char-to-int #'identity))
4002
4003;;------------------------------------------------------------------- 4084;;-------------------------------------------------------------------
4004;; Menu stuff (both for the editing buffer and for the inferior 4085;; Menu stuff (both for the editing buffer and for the inferior
4005;; prolog buffer) 4086;; prolog buffer)
@@ -4110,7 +4191,7 @@ Uses the current case-table for extracting the relevant information."
4110 ["Beginning of predicate" prolog-beginning-of-predicate t] 4191 ["Beginning of predicate" prolog-beginning-of-predicate t]
4111 ["End of predicate" prolog-end-of-predicate t] 4192 ["End of predicate" prolog-end-of-predicate t]
4112 "---" 4193 "---"
4113 ["Indent line" prolog-indent-line t] 4194 ["Indent line" indent-according-to-mode t]
4114 ["Indent region" indent-region (region-exists-p)] 4195 ["Indent region" indent-region (region-exists-p)]
4115 ["Indent predicate" prolog-indent-predicate t] 4196 ["Indent predicate" prolog-indent-predicate t]
4116 ["Indent buffer" prolog-indent-buffer t] 4197 ["Indent buffer" prolog-indent-buffer t]
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 2922330e6f9..620ea8cd519 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1601,7 +1601,7 @@ behavior, change `python-remove-cwd-from-path' to nil."
1601 ;; Fixme: Write a `coding' header to the temp file if the region is 1601 ;; Fixme: Write a `coding' header to the temp file if the region is
1602 ;; non-ASCII. 1602 ;; non-ASCII.
1603 (interactive "r") 1603 (interactive "r")
1604 (let* ((f (make-temp-file "py")) 1604 (let* ((f (make-temp-file "py" nil ".py"))
1605 (command 1605 (command
1606 ;; IPython puts the FakeModule module into __main__ so 1606 ;; IPython puts the FakeModule module into __main__ so
1607 ;; emacs.eexecfile becomes useless. 1607 ;; emacs.eexecfile becomes useless.
@@ -2468,15 +2468,6 @@ with skeleton expansions for compound statement templates.
2468 nil t) 2468 nil t)
2469 (add-hook 'completion-at-point-functions 2469 (add-hook 'completion-at-point-functions
2470 'python-completion-at-point nil 'local) 2470 'python-completion-at-point nil 'local)
2471 ;; Fixme: should be in hideshow. This seems to be of limited use
2472 ;; since it isn't (can't be) indentation-based. Also hide-level
2473 ;; doesn't seem to work properly.
2474 (add-to-list 'hs-special-modes-alist
2475 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
2476 ,(lambda (_arg)
2477 (python-end-of-defun)
2478 (skip-chars-backward " \t\n"))
2479 nil))
2480 (set (make-local-variable 'skeleton-further-elements) 2471 (set (make-local-variable 'skeleton-further-elements)
2481 '((< '(backward-delete-char-untabify (min python-indent 2472 '((< '(backward-delete-char-untabify (min python-indent
2482 (current-column)))) 2473 (current-column))))
@@ -2615,9 +2606,17 @@ problem."
2615 (let* ((filename (match-string 1 block)) 2606 (let* ((filename (match-string 1 block))
2616 (lineno (string-to-number (match-string 2 block))) 2607 (lineno (string-to-number (match-string 2 block)))
2617 (funcname (match-string 3 block)) 2608 (funcname (match-string 3 block))
2609 (msg (get-text-property 0 'compilation-message filename))
2610 (loc (and msg (compilation--message->loc msg)))
2618 funcbuffer) 2611 funcbuffer)
2619 2612
2620 (cond ((file-exists-p filename) 2613 (cond ((and loc (markerp (compilation--loc->marker loc)))
2614 (setq funcbuffer (marker-buffer (compilation--loc->marker loc)))
2615 (list (with-current-buffer funcbuffer
2616 (line-number-at-pos (compilation--loc->marker loc)))
2617 funcbuffer))
2618
2619 ((file-exists-p filename)
2621 (list lineno (find-file-noselect filename))) 2620 (list lineno (find-file-noselect filename)))
2622 2621
2623 ((setq funcbuffer (python-pdbtrack-grub-for-buffer funcname lineno)) 2622 ((setq funcbuffer (python-pdbtrack-grub-for-buffer funcname lineno))
@@ -2635,15 +2634,12 @@ problem."
2635 (buffer-substring 2634 (buffer-substring
2636 (point-min) (point-max))) 2635 (point-min) (point-max)))
2637 ))))))) 2636 )))))))
2638 (list lineno funcbuffer)) 2637 (list lineno funcbuffer))
2639 2638
2640 ((= (elt filename 0) ?\<) 2639 ((= (elt filename 0) ?\<)
2641 (format "(Non-file source: '%s')" filename)) 2640 (format "(Non-file source: '%s')" filename))
2642 2641
2643 (t (format "Not found: %s(), %s" funcname filename))) 2642 (t (format "Not found: %s(), %s" funcname filename))))))
2644 )
2645 )
2646 )
2647 2643
2648(defun python-pdbtrack-grub-for-buffer (funcname _lineno) 2644(defun python-pdbtrack-grub-for-buffer (funcname _lineno)
2649 "Find recent Python mode buffer named, or having function named FUNCNAME." 2645 "Find recent Python mode buffer named, or having function named FUNCNAME."
@@ -2717,6 +2713,17 @@ comint believe the user typed this string so that
2717 ;; continue standard unloading 2713 ;; continue standard unloading
2718 nil) 2714 nil)
2719 2715
2716;;;; Finish up
2717;; Fixme: should be in hideshow. This seems to be of limited use
2718;; since it isn't (can't be) indentation-based. Also hide-level
2719;; doesn't seem to work properly.
2720(add-to-list 'hs-special-modes-alist
2721 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
2722 ,(lambda (_arg)
2723 (python-end-of-defun)
2724 (skip-chars-backward " \t\n"))
2725 nil))
2726
2720(provide 'python) 2727(provide 'python)
2721(provide 'python-21) 2728(provide 'python-21)
2722 2729
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 66aa256f947..5d79437c3c2 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -784,7 +784,7 @@ and `\\' when preceded by `?'."
784 (not (looking-at "[a-z_]")))) 784 (not (looking-at "[a-z_]"))))
785 (and (looking-at ruby-operator-re) 785 (and (looking-at ruby-operator-re)
786 (not (ruby-special-char-p)) 786 (not (ruby-special-char-p))
787 ;; operator at the end of line 787 ;; Operator at the end of line.
788 (let ((c (char-after (point)))) 788 (let ((c (char-after (point))))
789 (and 789 (and
790;; (or (null begin) 790;; (or (null begin)
@@ -794,8 +794,9 @@ and `\\' when preceded by `?'."
794;; (not (or (eolp) (looking-at "#") 794;; (not (or (eolp) (looking-at "#")
795;; (and (eq (car (nth 1 state)) ?{) 795;; (and (eq (car (nth 1 state)) ?{)
796;; (looking-at "|")))))) 796;; (looking-at "|"))))))
797 (or (not (eq ?/ c)) 797 ;; Not a regexp or general delimited literal.
798 (null (nth 0 (ruby-parse-region (or begin parse-start) (point))))) 798 (null (nth 0 (ruby-parse-region (or begin parse-start)
799 (point))))
799 (or (not (eq ?| (char-after (point)))) 800 (or (not (eq ?| (char-after (point))))
800 (save-excursion 801 (save-excursion
801 (or (eolp) (forward-char -1)) 802 (or (eolp) (forward-char -1))
@@ -1110,6 +1111,8 @@ See `add-log-current-defun-function'."
1110 mlist))))) 1111 mlist)))))
1111 1112
1112(declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit)) 1113(declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit))
1114(declare-function ruby-syntax-general-delimiters-goto-beg "ruby-mode" ())
1115(declare-function ruby-syntax-propertize-general-delimiters "ruby-mode" (limit))
1113 1116
1114(if (eval-when-compile (fboundp #'syntax-propertize-rules)) 1117(if (eval-when-compile (fboundp #'syntax-propertize-rules))
1115 ;; New code that works independently from font-lock. 1118 ;; New code that works independently from font-lock.
@@ -1118,26 +1121,48 @@ See `add-log-current-defun-function'."
1118 "Syntactic keywords for Ruby mode. See `syntax-propertize-function'." 1121 "Syntactic keywords for Ruby mode. See `syntax-propertize-function'."
1119 (goto-char start) 1122 (goto-char start)
1120 (ruby-syntax-propertize-heredoc end) 1123 (ruby-syntax-propertize-heredoc end)
1124 (ruby-syntax-general-delimiters-goto-beg)
1121 (funcall 1125 (funcall
1122 (syntax-propertize-rules 1126 (syntax-propertize-rules
1123 ;; #{ }, #$hoge, #@foo are not comments 1127 ;; #{ }, #$hoge, #@foo are not comments.
1124 ("\\(#\\)[{$@]" (1 ".")) 1128 ("\\(#\\)[{$@]" (1 "."))
1125 ;; $' $" $` .... are variables 1129 ;; $' $" $` .... are variables.
1126 ;; ?' ?" ?` are ascii codes 1130 ;; ?' ?" ?` are ascii codes.
1127 ("\\([?$]\\)[#\"'`]" 1131 ("\\([?$]\\)[#\"'`]"
1128 (1 (unless (save-excursion 1132 (1 (unless (save-excursion
1129 ;; Not within a string. 1133 ;; Not within a string.
1130 (nth 3 (syntax-ppss (match-beginning 0)))) 1134 (nth 3 (syntax-ppss (match-beginning 0))))
1131 (string-to-syntax "\\")))) 1135 (string-to-syntax "\\"))))
1132 ;; regexps 1136 ;; Regexps: regexps are distinguished from division either because
1133 ("\\(^\\|[[=(,~?:;<>]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" 1137 ;; of the keyword/symbol before them, or because of the code
1134 (4 "\"/") 1138 ;; following them.
1135 (6 "\"/")) 1139 ((concat
1140 ;; Special tokens that can't be followed by a division operator.
1141 "\\(?:\\(^\\|[[=(,~?:;<>]\\|\\(?:^\\|\\s \\)"
1142 (regexp-opt '("if" "elsif" "unless" "while" "until" "when" "and"
1143 "or" "&&" "||"
1144 "gsub" "gsub!" "sub" "sub!" "scan" "split" "split!"))
1145 "\\)\\s *\\)?"
1146 ;; The regular expression itself.
1147 "\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)"
1148 ;; Special code that cannot follow a division operator.
1149 ;; FIXME: Just because the second slash of "/foo/ do bar" can't
1150 ;; be a division, doesn't mean it can't *start* a regexp, as in
1151 ;; "x = toto/foo; if /do bar/".
1152 "\\([imxo]*\\s *\\(?:,\\|\\_<do\\_>\\)\\)?")
1153 (2 (when (or (match-beginning 1) (match-beginning 4))
1154 (string-to-syntax "\"/")))
1155 (3 (if (or (match-beginning 1) (match-beginning 4))
1156 (string-to-syntax "\"/")
1157 (goto-char (match-end 2)))))
1136 ("^=en\\(d\\)\\_>" (1 "!")) 1158 ("^=en\\(d\\)\\_>" (1 "!"))
1137 ("^\\(=\\)begin\\_>" (1 "!")) 1159 ("^\\(=\\)begin\\_>" (1 "!"))
1138 ;; Handle here documents. 1160 ;; Handle here documents.
1139 ((concat ruby-here-doc-beg-re ".*\\(\n\\)") 1161 ((concat ruby-here-doc-beg-re ".*\\(\n\\)")
1140 (7 (prog1 "\"" (ruby-syntax-propertize-heredoc end))))) 1162 (7 (prog1 "\"" (ruby-syntax-propertize-heredoc end))))
1163 ;; Handle percent literals: %w(), %q{}, etc.
1164 ("\\(?:^\\|[[ \t\n<+(,=]\\)\\(%\\)[qQrswWx]?\\([[:punct:]]\\)"
1165 (1 (prog1 "|" (ruby-syntax-propertize-general-delimiters end)))))
1141 (point) end)) 1166 (point) end))
1142 1167
1143 (defun ruby-syntax-propertize-heredoc (limit) 1168 (defun ruby-syntax-propertize-heredoc (limit)
@@ -1163,6 +1188,41 @@ See `add-log-current-defun-function'."
1163 ;; Make extra sure we don't move back, lest we could fall into an 1188 ;; Make extra sure we don't move back, lest we could fall into an
1164 ;; inf-loop. 1189 ;; inf-loop.
1165 (if (< (point) start) (goto-char start)))))) 1190 (if (< (point) start) (goto-char start))))))
1191
1192 (defun ruby-syntax-general-delimiters-goto-beg ()
1193 (let ((state (syntax-ppss)))
1194 ;; Move to the start of the literal, in case it's multiline.
1195 ;; TODO: determine the literal type more reliably here?
1196 (when (eq t (nth 3 state))
1197 (goto-char (nth 8 state))
1198 (beginning-of-line))))
1199
1200 (defun ruby-syntax-propertize-general-delimiters (limit)
1201 (goto-char (match-beginning 2))
1202 (let* ((op (char-after))
1203 (ops (char-to-string op))
1204 (cl (or (cdr (aref (syntax-table) op))
1205 (cdr (assoc op '((?< . ?>))))))
1206 parse-sexp-lookup-properties)
1207 (ignore-errors
1208 (if cl
1209 (progn ; Paired delimiters.
1210 ;; Delimiter pairs of the same kind can be nested
1211 ;; inside the literal, as long as they are balanced.
1212 ;; Create syntax table that ignores other characters.
1213 (with-syntax-table (make-char-table 'syntax-table nil)
1214 (modify-syntax-entry op (concat "(" (char-to-string cl)))
1215 (modify-syntax-entry cl (concat ")" ops))
1216 (modify-syntax-entry ?\\ "\\")
1217 (save-restriction
1218 (narrow-to-region (point) limit)
1219 (forward-list)))) ; skip to the paired character
1220 ;; Single character delimiter.
1221 (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*"
1222 (regexp-quote ops)) limit nil))
1223 ;; If we reached here, the closing delimiter was found.
1224 (put-text-property (1- (point)) (point)
1225 'syntax-table (string-to-syntax "|")))))
1166 ) 1226 )
1167 1227
1168 ;; For Emacsen where syntax-propertize-rules is not (yet) available, 1228 ;; For Emacsen where syntax-propertize-rules is not (yet) available,
@@ -1207,6 +1267,10 @@ This should only be called after matching against `ruby-here-doc-end-re'."
1207 (4 (7 . ?/)) 1267 (4 (7 . ?/))
1208 (6 (7 . ?/))) 1268 (6 (7 . ?/)))
1209 ("^=en\\(d\\)\\_>" 1 "!") 1269 ("^=en\\(d\\)\\_>" 1 "!")
1270 ;; General delimited string.
1271 ("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)"
1272 (3 "\"")
1273 (5 "\""))
1210 ("^\\(=\\)begin\\_>" 1 (ruby-comment-beg-syntax)) 1274 ("^\\(=\\)begin\\_>" 1 (ruby-comment-beg-syntax))
1211 ;; Currently, the following case is highlighted incorrectly: 1275 ;; Currently, the following case is highlighted incorrectly:
1212 ;; 1276 ;;
@@ -1415,9 +1479,6 @@ See `font-lock-syntax-table'.")
1415 1 font-lock-variable-name-face) 1479 1 font-lock-variable-name-face)
1416 '("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+" 1480 '("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
1417 0 font-lock-variable-name-face) 1481 0 font-lock-variable-name-face)
1418 ;; general delimited string
1419 '("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)"
1420 (2 font-lock-string-face))
1421 ;; constants 1482 ;; constants
1422 '("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)" 1483 '("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)"
1423 2 font-lock-type-face) 1484 2 font-lock-type-face)
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index f60ce185bc7..a07ecfcb3a4 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -326,7 +326,9 @@ shell it really is."
326 326
327(defcustom sh-imenu-generic-expression 327(defcustom sh-imenu-generic-expression
328 `((sh 328 `((sh
329 . ((nil "^\\s-*\\(function\\s-+\\)?\\([[:alpha:]_][[:alnum:]_]+\\)\\s-*()" 2)))) 329 . ((nil
330 "^\\s-*\\(function\\s-+\\)?\\([[:alpha:]_][[:alnum:]_]+\\)\\s-*()"
331 2))))
330 "Alist of regular expressions for recognizing shell function definitions. 332 "Alist of regular expressions for recognizing shell function definitions.
331See `sh-feature' and `imenu-generic-expression'." 333See `sh-feature' and `imenu-generic-expression'."
332 :type '(alist :key-type (symbol :tag "Shell") 334 :type '(alist :key-type (symbol :tag "Shell")
@@ -460,14 +462,6 @@ This is buffer-local in every such buffer.")
460 (define-key map "\C-c+" 'sh-add) 462 (define-key map "\C-c+" 'sh-add)
461 (define-key map "\C-\M-x" 'sh-execute-region) 463 (define-key map "\C-\M-x" 'sh-execute-region)
462 (define-key map "\C-c\C-x" 'executable-interpret) 464 (define-key map "\C-c\C-x" 'executable-interpret)
463 ;; FIXME: Use post-self-insert-hook.
464 (define-key map "<" 'sh-maybe-here-document)
465 (define-key map "(" 'skeleton-pair-insert-maybe)
466 (define-key map "{" 'skeleton-pair-insert-maybe)
467 (define-key map "[" 'skeleton-pair-insert-maybe)
468 (define-key map "'" 'skeleton-pair-insert-maybe)
469 (define-key map "`" 'skeleton-pair-insert-maybe)
470 (define-key map "\"" 'skeleton-pair-insert-maybe)
471 465
472 (define-key map [remap complete-tag] 'comint-dynamic-complete) 466 (define-key map [remap complete-tag] 'comint-dynamic-complete)
473 (define-key map [remap delete-backward-char] 467 (define-key map [remap delete-backward-char]
@@ -478,10 +472,10 @@ This is buffer-local in every such buffer.")
478 (define-key map [menu-bar sh-script] (cons "Sh-Script" menu-map)) 472 (define-key map [menu-bar sh-script] (cons "Sh-Script" menu-map))
479 (define-key menu-map [sh-learn-buffer-indent] 473 (define-key menu-map [sh-learn-buffer-indent]
480 '(menu-item "Learn buffer indentation" sh-learn-buffer-indent 474 '(menu-item "Learn buffer indentation" sh-learn-buffer-indent
481 :help "Learn how to indent the buffer the way it currently is.")) 475 :help "Learn how to indent the buffer the way it currently is."))
482 (define-key menu-map [sh-learn-line-indent] 476 (define-key menu-map [sh-learn-line-indent]
483 '(menu-item "Learn line indentation" sh-learn-line-indent 477 '(menu-item "Learn line indentation" sh-learn-line-indent
484 :help "Learn how to indent a line as it currently is indented")) 478 :help "Learn how to indent a line as it currently is indented"))
485 (define-key menu-map [sh-show-indent] 479 (define-key menu-map [sh-show-indent]
486 '(menu-item "Show indentation" sh-show-indent 480 '(menu-item "Show indentation" sh-show-indent
487 :help "Show the how the current line would be indented")) 481 :help "Show the how the current line would be indented"))
@@ -491,13 +485,9 @@ This is buffer-local in every such buffer.")
491 485
492 (define-key menu-map [sh-pair] 486 (define-key menu-map [sh-pair]
493 '(menu-item "Insert braces and quotes in pairs" 487 '(menu-item "Insert braces and quotes in pairs"
494 (lambda () 488 electric-pair-mode
495 (interactive) 489 :button (:toggle . (bound-and-true-p electric-pair-mode))
496 (require 'skeleton) 490 :help "Inserting a brace or quote automatically inserts the matching pair"))
497 (setq skeleton-pair (not skeleton-pair)))
498 :button (:toggle . (and (boundp 'skeleton-pair)
499 skeleton-pair))
500 :help "Inserting a brace or quote automatically inserts the matching pair"))
501 491
502 (define-key menu-map [sh-s0] '("--")) 492 (define-key menu-map [sh-s0] '("--"))
503 ;; Insert 493 ;; Insert
@@ -506,7 +496,7 @@ This is buffer-local in every such buffer.")
506 :help "Insert a function definition")) 496 :help "Insert a function definition"))
507 (define-key menu-map [sh-add] 497 (define-key menu-map [sh-add]
508 '(menu-item "Addition..." sh-add 498 '(menu-item "Addition..." sh-add
509 :help "Insert an addition of VAR and prefix DELTA for Bourne (type) shell")) 499 :help "Insert an addition of VAR and prefix DELTA for Bourne (type) shell"))
510 (define-key menu-map [sh-until] 500 (define-key menu-map [sh-until]
511 '(menu-item "Until Loop" sh-until 501 '(menu-item "Until Loop" sh-until
512 :help "Insert an until loop")) 502 :help "Insert an until loop"))
@@ -537,16 +527,16 @@ This is buffer-local in every such buffer.")
537 (define-key menu-map [sh-s1] '("--")) 527 (define-key menu-map [sh-s1] '("--"))
538 (define-key menu-map [sh-exec] 528 (define-key menu-map [sh-exec]
539 '(menu-item "Execute region" sh-execute-region 529 '(menu-item "Execute region" sh-execute-region
540 :help "Pass optional header and region to a subshell for noninteractive execution")) 530 :help "Pass optional header and region to a subshell for noninteractive execution"))
541 (define-key menu-map [sh-exec-interpret] 531 (define-key menu-map [sh-exec-interpret]
542 '(menu-item "Execute script..." executable-interpret 532 '(menu-item "Execute script..." executable-interpret
543 :help "Run script with user-specified args, and collect output in a buffer")) 533 :help "Run script with user-specified args, and collect output in a buffer"))
544 (define-key menu-map [sh-set-shell] 534 (define-key menu-map [sh-set-shell]
545 '(menu-item "Set shell type..." sh-set-shell 535 '(menu-item "Set shell type..." sh-set-shell
546 :help "Set this buffer's shell to SHELL (a string)")) 536 :help "Set this buffer's shell to SHELL (a string)"))
547 (define-key menu-map [sh-backslash-region] 537 (define-key menu-map [sh-backslash-region]
548 '(menu-item "Backslash region" sh-backslash-region 538 '(menu-item "Backslash region" sh-backslash-region
549 :help "Insert, align, or delete end-of-line backslashes on the lines in the region.")) 539 :help "Insert, align, or delete end-of-line backslashes on the lines in the region."))
550 map) 540 map)
551 "Keymap used in Shell-Script mode.") 541 "Keymap used in Shell-Script mode.")
552 542
@@ -564,9 +554,10 @@ This is buffer-local in every such buffer.")
564 :group 'sh-script) 554 :group 'sh-script)
565 555
566(defcustom sh-assignment-regexp 556(defcustom sh-assignment-regexp
567 '((csh . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=") 557 `((csh . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*[-+*/%^]?=")
568 ;; actually spaces are only supported in let/(( ... )) 558 ;; actually spaces are only supported in let/(( ... ))
569 (ksh88 . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?[ \t]*\\([-+*/%&|~^]\\|<<\\|>>\\)?=") 559 (ksh88 . ,(concat "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?"
560 "[ \t]*\\(?:[-+*/%&|~^]\\|<<\\|>>\\)?="))
570 (bash . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?\\+?=") 561 (bash . "\\<\\([[:alnum:]_]+\\)\\(\\[.+\\]\\)?\\+?=")
571 (rc . "\\<\\([[:alnum:]_*]+\\)[ \t]*=") 562 (rc . "\\<\\([[:alnum:]_*]+\\)[ \t]*=")
572 (sh . "\\<\\([[:alnum:]_]+\\)=")) 563 (sh . "\\<\\([[:alnum:]_]+\\)="))
@@ -1379,10 +1370,10 @@ punctuation characters like '-'."
1379 1370
1380 1371
1381(defconst sh-indent-supported 1372(defconst sh-indent-supported
1382 '((sh . t) 1373 '((sh . sh)
1383 (csh . nil) 1374 (csh . nil)
1384 (rc . t)) 1375 (rc . rc))
1385 "Shell types that shell indenting can do something with.") 1376 "Indentation rule set to use for each shell type.")
1386 1377
1387(defvar sh-indent-supported-here nil 1378(defvar sh-indent-supported-here nil
1388 "Non-nil if we support indentation for the current buffer's shell type.") 1379 "Non-nil if we support indentation for the current buffer's shell type.")
@@ -1464,9 +1455,8 @@ buffer indents as it currently is indented.
1464\\[sh-set-shell] Set this buffer's shell, and maybe its magic number. 1455\\[sh-set-shell] Set this buffer's shell, and maybe its magic number.
1465\\[sh-execute-region] Have optional header and region be executed in a subshell. 1456\\[sh-execute-region] Have optional header and region be executed in a subshell.
1466 1457
1467\\[sh-maybe-here-document] Without prefix, following an unquoted < inserts here document. 1458`sh-electric-here-document-mode' controls whether insertion of two
1468\{, (, [, ', \", ` 1459unquoted < insert a here document.
1469 Unless quoted with \\, insert the pairs {}, (), [], or '', \"\", ``.
1470 1460
1471If you generally program a shell different from your login shell you can 1461If you generally program a shell different from your login shell you can
1472set `sh-shell-file' accordingly. If your shell's file name doesn't correctly 1462set `sh-shell-file' accordingly. If your shell's file name doesn't correctly
@@ -1503,13 +1493,13 @@ with your script for an edit-interpret-debug cycle."
1503 #'sh-syntax-propertize-function) 1493 #'sh-syntax-propertize-function)
1504 (add-hook 'syntax-propertize-extend-region-functions 1494 (add-hook 'syntax-propertize-extend-region-functions
1505 #'syntax-propertize-multiline 'append 'local) 1495 #'syntax-propertize-multiline 'append 'local)
1496 (sh-electric-here-document-mode 1)
1506 (set (make-local-variable 'skeleton-pair-alist) '((?` _ ?`))) 1497 (set (make-local-variable 'skeleton-pair-alist) '((?` _ ?`)))
1507 (set (make-local-variable 'skeleton-pair-filter-function) 'sh-quoted-p) 1498 (set (make-local-variable 'skeleton-pair-filter-function) 'sh-quoted-p)
1508 (set (make-local-variable 'skeleton-further-elements) 1499 (set (make-local-variable 'skeleton-further-elements)
1509 '((< '(- (min sh-indentation (current-column)))))) 1500 '((< '(- (min sh-indentation (current-column))))))
1510 (set (make-local-variable 'skeleton-filter-function) 'sh-feature) 1501 (set (make-local-variable 'skeleton-filter-function) 'sh-feature)
1511 (set (make-local-variable 'skeleton-newline-indent-rigidly) t) 1502 (set (make-local-variable 'skeleton-newline-indent-rigidly) t)
1512 (set (make-local-variable 'sh-indent-supported-here) nil)
1513 (set (make-local-variable 'defun-prompt-regexp) 1503 (set (make-local-variable 'defun-prompt-regexp)
1514 (concat "^\\(function[ \t]\\|[[:alnum:]]+[ \t]+()[ \t]+\\)")) 1504 (concat "^\\(function[ \t]\\|[[:alnum:]]+[ \t]+()[ \t]+\\)"))
1515 ;; Parse or insert magic number for exec, and set all variables depending 1505 ;; Parse or insert magic number for exec, and set all variables depending
@@ -1519,23 +1509,15 @@ with your script for an edit-interpret-debug cycle."
1519 (goto-char (point-min)) 1509 (goto-char (point-min))
1520 (looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")) 1510 (looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)"))
1521 (match-string 2)) 1511 (match-string 2))
1522 ((not buffer-file-name) 1512 ((not buffer-file-name) sh-shell-file)
1523 sh-shell-file)
1524 ;; Checks that use `buffer-file-name' follow. 1513 ;; Checks that use `buffer-file-name' follow.
1525 ((string-match "\\.m?spec\\'" buffer-file-name) 1514 ((string-match "\\.m?spec\\'" buffer-file-name) "rpm")
1526 "rpm") 1515 ((string-match "[.]sh\\>" buffer-file-name) "sh")
1527 ((string-match "[.]sh\\>" buffer-file-name) 1516 ((string-match "[.]bash\\>" buffer-file-name) "bash")
1528 "sh") 1517 ((string-match "[.]ksh\\>" buffer-file-name) "ksh")
1529 ((string-match "[.]bash\\>" buffer-file-name) 1518 ((string-match "[.]csh\\>" buffer-file-name) "csh")
1530 "bash") 1519 ((equal (file-name-nondirectory buffer-file-name) ".profile") "sh")
1531 ((string-match "[.]ksh\\>" buffer-file-name) 1520 (t sh-shell-file))
1532 "ksh")
1533 ((string-match "[.]csh\\>" buffer-file-name)
1534 "csh")
1535 ((equal (file-name-nondirectory buffer-file-name) ".profile")
1536 "sh")
1537 (t
1538 sh-shell-file))
1539 nil nil)) 1521 nil nil))
1540 1522
1541;;;###autoload 1523;;;###autoload
@@ -1578,6 +1560,426 @@ This adds rules for comments and assignments."
1578 "Function to get better fontification including keywords and builtins." 1560 "Function to get better fontification including keywords and builtins."
1579 (sh-font-lock-keywords-1 t)) 1561 (sh-font-lock-keywords-1 t))
1580 1562
1563;;; Indentation and navigation with SMIE.
1564
1565(require 'smie)
1566
1567;; The SMIE code should generally be preferred, but it currently does not obey
1568;; the various indentation custom-vars, and it misses some important features
1569;; of the old code, mostly: sh-learn-line/buffer-indent, sh-show-indent,
1570;; sh-name/save/load-style.
1571(defvar sh-use-smie nil
1572 "Whether to use the SMIE code for navigation and indentation.")
1573
1574(defun sh-smie--keyword-p (tok)
1575 "Non-nil if TOK (at which we're looking) really is a keyword."
1576 (let ((prev (funcall smie-backward-token-function)))
1577 (if (zerop (length prev))
1578 (looking-back "\\s(" (1- (point)))
1579 (assoc prev smie-grammar))))
1580
1581(defun sh-smie--newline-semi-p (&optional tok)
1582 "Return non-nil if a newline should be treated as a semi-colon.
1583Here we assume that a newline should be treated as a semi-colon unless it
1584comes right after a special keyword.
1585This function does not pay attention to line-continuations.
1586If TOK is nil, point should be before the newline; otherwise, TOK is the token
1587before the newline and in that case point should be just before the token."
1588 (save-excursion
1589 (unless tok
1590 (setq tok (funcall smie-backward-token-function)))
1591 (if (and (zerop (length tok))
1592 (looking-back "\\s(" (1- (point))))
1593 nil
1594 (not (numberp (nth 2 (assoc tok smie-grammar)))))))
1595
1596;;;; SMIE support for `sh'.
1597
1598(defconst sh-smie-sh-grammar
1599 (smie-prec2->grammar
1600 (smie-bnf->prec2
1601 '((exp) ;A constant, or a $var, or a sequence of them...
1602 (cmd ("case" exp "in" branches "esac")
1603 ("if" cmd "then" cmd "fi")
1604 ("if" cmd "then" cmd "else" cmd "fi")
1605 ("if" cmd "then" cmd "elif" cmd "then" cmd "fi")
1606 ("if" cmd "then" cmd "elif" cmd "then" cmd "else" cmd "fi")
1607 ("if" cmd "then" cmd "elif" cmd "then" cmd
1608 "elif" cmd "then" cmd "else" cmd "fi")
1609 ("while" cmd "do" cmd "done")
1610 ("until" cmd "do" cmd "done")
1611 ("for" exp "in" cmd "do" cmd "done")
1612 ("for" exp "do" cmd "done")
1613 ("select" exp "in" cmd "do" cmd "done") ;bash&zsh&ksh88.
1614 ("repeat" exp "do" cmd "done") ;zsh.
1615 (exp "always" exp) ;zsh.
1616 (cmd "|" cmd) (cmd "|&" cmd)
1617 (cmd "&&" cmd) (cmd "||" cmd)
1618 (cmd ";" cmd) (cmd "&" cmd))
1619 (pattern (pattern "|" pattern))
1620 (branches (branches ";;" branches)
1621 (branches ";&" branches) (branches ";;&" branches) ;bash.
1622 (pattern "case-)" cmd)))
1623 '((assoc ";;" ";&" ";;&"))
1624 '((assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
1625
1626(defconst sh-smie--sh-operators
1627 (delq nil (mapcar (lambda (x)
1628 (setq x (car x))
1629 (and (stringp x)
1630 (not (string-match "\\`[a-z]" x))
1631 x))
1632 sh-smie-sh-grammar)))
1633
1634(defconst sh-smie--sh-operators-re (regexp-opt sh-smie--sh-operators))
1635(defconst sh-smie--sh-operators-back-re
1636 (concat "\\(?:^\\|[^\\]\\)\\(?:\\\\\\\\\\)*"
1637 "\\(" sh-smie--sh-operators-re "\\)"))
1638
1639(defun sh-smie--sh-keyword-in-p ()
1640 "Assuming we're looking at \"in\", return non-nil if it's a keyword.
1641Does not preserve point."
1642 (let ((forward-sexp-function nil)
1643 (words nil) ;We've seen words.
1644 (newline nil) ;We've seen newlines after the words.
1645 (res nil)
1646 prev)
1647 (while (not res)
1648 (setq prev (funcall smie-backward-token-function))
1649 (cond
1650 ((zerop (length prev))
1651 (if newline
1652 (progn (assert words) (setq res 'word))
1653 (setq words t)
1654 (condition-case nil
1655 (forward-sexp -1)
1656 (scan-error (setq res 'unknown)))))
1657 ((equal prev ";")
1658 (if words (setq newline t)
1659 (setq res 'keyword)))
1660 ((member prev '("case" "for" "select")) (setq res 'keyword))
1661 ((assoc prev smie-grammar) (setq res 'word))
1662 (t
1663 (if newline
1664 (progn (assert words) (setq res 'word))
1665 (setq words t)))))
1666 (eq res 'keyword)))
1667
1668(defun sh-smie--sh-keyword-p (tok)
1669 "Non-nil if TOK (at which we're looking) really is a keyword."
1670 (if (equal tok "in")
1671 (sh-smie--sh-keyword-in-p)
1672 (sh-smie--keyword-p tok)))
1673
1674(defun sh-smie-sh-forward-token ()
1675 (if (and (looking-at "[ \t]*\\(?:#\\|\\(\\s|\\)\\|$\\)")
1676 (save-excursion
1677 (skip-chars-backward " \t")
1678 (not (bolp))))
1679 (if (and (match-end 1) (not (nth 3 (syntax-ppss))))
1680 ;; Right before a here-doc.
1681 (let ((forward-sexp-function nil))
1682 (forward-sexp 1)
1683 ;; Pretend the here-document is a "newline representing a
1684 ;; semi-colon", since the here-doc otherwise covers the newline(s).
1685 ";")
1686 (let ((semi (sh-smie--newline-semi-p)))
1687 (forward-line 1)
1688 (if semi ";"
1689 (sh-smie-sh-forward-token))))
1690 (forward-comment (point-max))
1691 (cond
1692 ((looking-at "\\\\\n") (forward-line 1) (sh-smie-sh-forward-token))
1693 ((looking-at sh-smie--sh-operators-re)
1694 (goto-char (match-end 0))
1695 (let ((tok (match-string-no-properties 0)))
1696 (if (and (memq (aref tok (1- (length tok))) '(?\; ?\& ?\|))
1697 (looking-at "[ \t]*\\(?:#\\|$\\)"))
1698 (forward-line 1))
1699 tok))
1700 (t
1701 (let* ((pos (point))
1702 (tok (smie-default-forward-token)))
1703 (cond
1704 ((equal tok ")") "case-)")
1705 ((and tok (string-match "\\`[a-z]" tok)
1706 (assoc tok smie-grammar)
1707 (not
1708 (save-excursion
1709 (goto-char pos)
1710 (sh-smie--sh-keyword-p tok))))
1711 " word ")
1712 (t tok)))))))
1713
1714(defun sh-smie--looking-back-at-continuation-p ()
1715 (save-excursion
1716 (and (if (eq (char-before) ?\n) (progn (forward-char -1) t) (eolp))
1717 (looking-back "\\(?:^\\|[^\\]\\)\\(?:\\\\\\\\\\)*\\\\"
1718 (line-beginning-position)))))
1719
1720(defun sh-smie-sh-backward-token ()
1721 (let ((bol (line-beginning-position))
1722 pos tok)
1723 (forward-comment (- (point)))
1724 (cond
1725 ((and (bolp) (not (bobp))
1726 (equal (syntax-after (1- (point))) (string-to-syntax "|"))
1727 (not (nth 3 (syntax-ppss))))
1728 ;; Right after a here-document.
1729 (let ((forward-sexp-function nil))
1730 (forward-sexp -1)
1731 ;; Pretend the here-document is a "newline representing a
1732 ;; semi-colon", since the here-doc otherwise covers the newline(s).
1733 ";"))
1734 ((< (point) bol)
1735 (cond
1736 ((sh-smie--looking-back-at-continuation-p)
1737 (forward-char -1)
1738 (funcall smie-backward-token-function))
1739 ((sh-smie--newline-semi-p) ";")
1740 (t (funcall smie-backward-token-function))))
1741 ((looking-back sh-smie--sh-operators-back-re
1742 (line-beginning-position) 'greedy)
1743 (goto-char (match-beginning 1))
1744 (match-string-no-properties 1))
1745 (t
1746 (let ((tok (smie-default-backward-token)))
1747 (cond
1748 ((equal tok ")") "case-)")
1749 ((and tok (string-match "\\`[a-z]" tok)
1750 (assoc tok smie-grammar)
1751 (not (save-excursion (sh-smie--sh-keyword-p tok))))
1752 " word ")
1753 (t tok)))))))
1754
1755(defcustom sh-indent-after-continuation t
1756 "If non-nil, try to make sure text is indented after a line continuation."
1757 :type 'boolean)
1758
1759(defun sh-smie--continuation-start-indent ()
1760 "Return the initial indentation of a continued line.
1761May return nil if the line should not be treated as continued."
1762 (save-excursion
1763 (forward-line -1)
1764 (unless (sh-smie--looking-back-at-continuation-p)
1765 (current-indentation))))
1766
1767(defun sh-smie-sh-rules (kind token)
1768 (pcase (cons kind token)
1769 (`(:elem . basic) sh-indentation)
1770 (`(:after . "case-)") (or sh-indentation smie-indent-basic))
1771 ((and `(:before . ,_)
1772 (guard (when sh-indent-after-continuation
1773 (save-excursion
1774 (ignore-errors
1775 (skip-chars-backward " \t")
1776 (sh-smie--looking-back-at-continuation-p))))))
1777 ;; After a line-continuation, make sure the rest is indented.
1778 (let* ((sh-indent-after-continuation nil)
1779 (indent (smie-indent-calculate))
1780 (initial (sh-smie--continuation-start-indent)))
1781 (when (and (numberp indent) (numberp initial)
1782 (<= indent initial))
1783 `(column . ,(+ initial sh-indentation)))))
1784 (`(:before . ,(or `"(" `"{" `"["))
1785 (if (smie-rule-hanging-p) (smie-rule-parent)))
1786 ;; FIXME: Maybe this handling of ;; should be made into
1787 ;; a smie-rule-terminator function that takes the substitute ";" as arg.
1788 (`(:before . ,(or `";;" `";&" `";;&"))
1789 (if (and (smie-rule-bolp) (looking-at ";;?&?[ \t]*\\(#\\|$\\)"))
1790 (cons 'column (smie-indent-keyword ";"))
1791 (smie-rule-separator kind)))
1792 (`(:after . ,(or `";;" `";&" `";;&"))
1793 (with-demoted-errors
1794 (smie-backward-sexp token)
1795 (cons 'column
1796 (if (or (smie-rule-bolp)
1797 (save-excursion
1798 (and (member (funcall smie-backward-token-function)
1799 '("in" ";;"))
1800 (smie-rule-bolp))))
1801 (current-column)
1802 (smie-indent-calculate)))))
1803 (`(:after . "|") (if (smie-rule-parent-p "|") nil 4))
1804 ))
1805
1806;; (defconst sh-smie-csh-grammar
1807;; (smie-prec2->grammar
1808;; (smie-bnf->prec2
1809;; '((exp) ;A constant, or a $var, or a sequence of them…
1810;; (elseifcmd (cmd)
1811;; (cmd "else" "else-if" exp "then" elseifcmd))
1812;; (cmd ("switch" branches "endsw")
1813;; ("if" exp)
1814;; ("if" exp "then" cmd "endif")
1815;; ("if" exp "then" cmd "else" cmd "endif")
1816;; ("if" exp "then" elseifcmd "endif")
1817;; ;; ("if" exp "then" cmd "else" cmd "endif")
1818;; ;; ("if" exp "then" cmd "else" "if" exp "then" cmd "endif")
1819;; ;; ("if" exp "then" cmd "else" "if" exp "then" cmd
1820;; ;; "else" cmd "endif")
1821;; ;; ("if" exp "then" cmd "else" "if" exp "then" cmd
1822;; ;; "else" "if" exp "then" cmd "endif")
1823;; ("while" cmd "end")
1824;; ("foreach" cmd "end")
1825;; (cmd "|" cmd) (cmd "|&" cmd)
1826;; (cmd "&&" cmd) (cmd "||" cmd)
1827;; (cmd ";" cmd) (cmd "&" cmd))
1828;; ;; This is a lie, but (combined with the corresponding disambiguation
1829;; ;; rule) it makes it more clear that `case' and `default' are the key
1830;; ;; separators and the `:' is a secondary tokens.
1831;; (branches (branches "case" branches)
1832;; (branches "default" branches)
1833;; (exp ":" branches)))
1834;; '((assoc "else" "then" "endif"))
1835;; '((assoc "case" "default") (nonassoc ":"))
1836;; '((assoc ";;" ";&" ";;&"))
1837;; '((assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
1838
1839;;;; SMIE support for `rc'.
1840
1841(defconst sh-smie-rc-grammar
1842 (smie-prec2->grammar
1843 (smie-bnf->prec2
1844 '((exp) ;A constant, or a $var, or a sequence of them...
1845 (cmd (cmd "case" cmd)
1846 ("if" exp)
1847 ("switch" exp)
1848 ("for" exp) ("while" exp)
1849 (cmd "|" cmd) (cmd "|&" cmd)
1850 (cmd "&&" cmd) (cmd "||" cmd)
1851 (cmd ";" cmd) (cmd "&" cmd))
1852 (pattern (pattern "|" pattern))
1853 (branches (branches ";;" branches)
1854 (branches ";&" branches) (branches ";;&" branches) ;bash.
1855 (pattern "case-)" cmd)))
1856 '((assoc ";;" ";&" ";;&"))
1857 '((assoc "case") (assoc ";" "&") (assoc "&&" "||") (assoc "|" "|&")))))
1858
1859(defun sh-smie--rc-after-special-arg-p ()
1860 "Check if we're after the first arg of an if/while/for/... construct.
1861Returns the construct's token and moves point before it, if so."
1862 (forward-comment (- (point)))
1863 (when (looking-back ")\\|\\_<not" (- (point) 3))
1864 (ignore-errors
1865 (let ((forward-sexp-function nil))
1866 (forward-sexp -1)
1867 (car (member (funcall smie-backward-token-function)
1868 '("if" "for" "switch" "while")))))))
1869
1870(defun sh-smie--rc-newline-semi-p ()
1871 "Return non-nil if a newline should be treated as a semi-colon.
1872Point should be before the newline."
1873 (save-excursion
1874 (let ((tok (funcall smie-backward-token-function)))
1875 (if (or (when (equal tok "not") (forward-word 1) t)
1876 (and (zerop (length tok)) (eq (char-before) ?\))))
1877 (not (sh-smie--rc-after-special-arg-p))
1878 (sh-smie--newline-semi-p tok)))))
1879
1880(defun sh-smie-rc-forward-token ()
1881 ;; FIXME: Code duplication with sh-smie-sh-forward-token.
1882 (if (and (looking-at "[ \t]*\\(?:#\\|\\(\\s|\\)\\|$\\)")
1883 (save-excursion
1884 (skip-chars-backward " \t")
1885 (not (bolp))))
1886 (if (and (match-end 1) (not (nth 3 (syntax-ppss))))
1887 ;; Right before a here-doc.
1888 (let ((forward-sexp-function nil))
1889 (forward-sexp 1)
1890 ;; Pretend the here-document is a "newline representing a
1891 ;; semi-colon", since the here-doc otherwise covers the newline(s).
1892 ";")
1893 (let ((semi (sh-smie--rc-newline-semi-p)))
1894 (forward-line 1)
1895 (if semi ";"
1896 (sh-smie-rc-forward-token))))
1897 (forward-comment (point-max))
1898 (cond
1899 ((looking-at "\\\\\n") (forward-line 1) (sh-smie-rc-forward-token))
1900 ;; ((looking-at sh-smie--rc-operators-re)
1901 ;; (goto-char (match-end 0))
1902 ;; (let ((tok (match-string-no-properties 0)))
1903 ;; (if (and (memq (aref tok (1- (length tok))) '(?\; ?\& ?\|))
1904 ;; (looking-at "[ \t]*\\(?:#\\|$\\)"))
1905 ;; (forward-line 1))
1906 ;; tok))
1907 (t
1908 (let* ((pos (point))
1909 (tok (smie-default-forward-token)))
1910 (cond
1911 ;; ((equal tok ")") "case-)")
1912 ((and tok (string-match "\\`[a-z]" tok)
1913 (assoc tok smie-grammar)
1914 (not
1915 (save-excursion
1916 (goto-char pos)
1917 (sh-smie--keyword-p tok))))
1918 " word ")
1919 (t tok)))))))
1920
1921(defun sh-smie-rc-backward-token ()
1922 ;; FIXME: Code duplication with sh-smie-sh-backward-token.
1923 (let ((bol (line-beginning-position))
1924 pos tok)
1925 (forward-comment (- (point)))
1926 (cond
1927 ((and (bolp) (not (bobp))
1928 (equal (syntax-after (1- (point))) (string-to-syntax "|"))
1929 (not (nth 3 (syntax-ppss))))
1930 ;; Right after a here-document.
1931 (let ((forward-sexp-function nil))
1932 (forward-sexp -1)
1933 ;; Pretend the here-document is a "newline representing a
1934 ;; semi-colon", since the here-doc otherwise covers the newline(s).
1935 ";"))
1936 ((< (point) bol) ;We skipped over a newline.
1937 (cond
1938 ;; A continued line.
1939 ((and (eolp)
1940 (looking-back "\\(?:^\\|[^\\]\\)\\(?:\\\\\\\\\\)*\\\\"
1941 (line-beginning-position)))
1942 (forward-char -1)
1943 (funcall smie-backward-token-function))
1944 ((sh-smie--rc-newline-semi-p) ";")
1945 (t (funcall smie-backward-token-function))))
1946 ;; ((looking-back sh-smie--sh-operators-back-re
1947 ;; (line-beginning-position) 'greedy)
1948 ;; (goto-char (match-beginning 1))
1949 ;; (match-string-no-properties 1))
1950 (t
1951 (let ((tok (smie-default-backward-token)))
1952 (cond
1953 ;; ((equal tok ")") "case-)")
1954 ((and tok (string-match "\\`[a-z]" tok)
1955 (assoc tok smie-grammar)
1956 (not (save-excursion (sh-smie--keyword-p tok))))
1957 " word ")
1958 (t tok)))))))
1959
1960(defun sh-smie-rc-rules (kind token)
1961 (pcase (cons kind token)
1962 (`(:elem . basic) sh-indentation)
1963 ;; (`(:after . "case") (or sh-indentation smie-indent-basic))
1964 (`(:after . ";") (if (smie-rule-parent-p "case")
1965 (smie-rule-parent sh-indentation)))
1966 (`(:before . "{")
1967 (save-excursion
1968 (when (sh-smie--rc-after-special-arg-p)
1969 `(column . ,(current-column)))))
1970 (`(:before . ,(or `"(" `"{" `"["))
1971 (if (smie-rule-hanging-p) (smie-rule-parent)))
1972 ;; FIXME: SMIE parses "if (exp) cmd" as "(if ((exp) cmd))" so "cmd" is
1973 ;; treated as an arg to (exp) by default, which indents it all wrong.
1974 ;; To handle it right, we should extend smie-indent-exps so that the
1975 ;; preceding keyword can give special rules. Currently the only special
1976 ;; rule we have is the :list-intro hack, which we use here to align "cmd"
1977 ;; with "(exp)", which is rarely the right thing to do, but is better
1978 ;; than nothing.
1979 (`(:list-intro . ,(or `"for" `"if" `"while")) t)
1980 ))
1981
1982;;; End of SMIE code.
1581 1983
1582(defvar sh-regexp-for-done nil 1984(defvar sh-regexp-for-done nil
1583 "A buffer-local regexp to match opening keyword for done.") 1985 "A buffer-local regexp to match opening keyword for done.")
@@ -1677,19 +2079,28 @@ Calls the value of `sh-set-shell-hook' if set."
1677 (set-syntax-table sh-mode-syntax-table))) 2079 (set-syntax-table sh-mode-syntax-table)))
1678 (dolist (var (sh-feature sh-variables)) 2080 (dolist (var (sh-feature sh-variables))
1679 (sh-remember-variable var)) 2081 (sh-remember-variable var))
1680 (if (setq sh-indent-supported-here (sh-feature sh-indent-supported)) 2082 (if (set (make-local-variable 'sh-indent-supported-here)
2083 (sh-feature sh-indent-supported))
1681 (progn 2084 (progn
1682 (message "Setting up indent for shell type %s" sh-shell) 2085 (message "Setting up indent for shell type %s" sh-shell)
1683 (set (make-local-variable 'parse-sexp-lookup-properties) t) 2086 (if sh-use-smie
1684 (set (make-local-variable 'sh-kw-alist) (sh-feature sh-kw)) 2087 (let ((mksym (lambda (name)
1685 (let ((regexp (sh-feature sh-kws-for-done))) 2088 (intern (format "sh-smie-%s-%s"
1686 (if regexp 2089 sh-indent-supported-here name)))))
1687 (set (make-local-variable 'sh-regexp-for-done) 2090 (smie-setup (symbol-value (funcall mksym "grammar"))
1688 (sh-mkword-regexpr (regexp-opt regexp t))))) 2091 (funcall mksym "rules")
1689 (message "setting up indent stuff") 2092 :forward-token (funcall mksym "forward-token")
1690 ;; sh-mode has already made indent-line-function local 2093 :backward-token (funcall mksym "backward-token")))
1691 ;; but do it in case this is called before that. 2094 (set (make-local-variable 'parse-sexp-lookup-properties) t)
1692 (set (make-local-variable 'indent-line-function) 'sh-indent-line) 2095 (set (make-local-variable 'sh-kw-alist) (sh-feature sh-kw))
2096 (let ((regexp (sh-feature sh-kws-for-done)))
2097 (if regexp
2098 (set (make-local-variable 'sh-regexp-for-done)
2099 (sh-mkword-regexpr (regexp-opt regexp t)))))
2100 (message "setting up indent stuff")
2101 ;; sh-mode has already made indent-line-function local
2102 ;; but do it in case this is called before that.
2103 (set (make-local-variable 'indent-line-function) 'sh-indent-line))
1693 (if sh-make-vars-local 2104 (if sh-make-vars-local
1694 (sh-make-vars-local)) 2105 (sh-make-vars-local))
1695 (message "Indentation setup for shell type %s" sh-shell)) 2106 (message "Indentation setup for shell type %s" sh-shell))
@@ -3237,8 +3648,9 @@ overwritten if
3237(defun sh-save-styles-to-buffer (buff) 3648(defun sh-save-styles-to-buffer (buff)
3238 "Save all current styles in elisp to buffer BUFF. 3649 "Save all current styles in elisp to buffer BUFF.
3239This is always added to the end of the buffer." 3650This is always added to the end of the buffer."
3240 (interactive (list 3651 (interactive
3241 (read-from-minibuffer "Buffer to save styles in? " "*scratch*"))) 3652 (list
3653 (read-from-minibuffer "Buffer to save styles in? " "*scratch*")))
3242 (with-current-buffer (get-buffer-create buff) 3654 (with-current-buffer (get-buffer-create buff)
3243 (goto-char (point-max)) 3655 (goto-char (point-max))
3244 (insert "\n") 3656 (insert "\n")
@@ -3656,8 +4068,12 @@ option followed by a colon `:' if the option accepts an argument."
3656The document is bounded by `sh-here-document-word'." 4068The document is bounded by `sh-here-document-word'."
3657 (interactive "*P") 4069 (interactive "*P")
3658 (self-insert-command (prefix-numeric-value arg)) 4070 (self-insert-command (prefix-numeric-value arg))
3659 (or arg 4071 (or arg (sh--maybe-here-document)))
3660 (not (looking-back "[^<]<<")) 4072(make-obsolete 'sh--maybe-here-document
4073 'sh-electric-here-document-mode "24.2")
4074
4075(defun sh--maybe-here-document ()
4076 (or (not (looking-back "[^<]<<"))
3661 (save-excursion 4077 (save-excursion
3662 (backward-char 2) 4078 (backward-char 2)
3663 (sh-quoted-p)) 4079 (sh-quoted-p))
@@ -3678,6 +4094,12 @@ The document is bounded by `sh-here-document-word'."
3678 (insert ?\n tabs (replace-regexp-in-string 4094 (insert ?\n tabs (replace-regexp-in-string
3679 "\\`-?[ \t]*" "" delim)))))) 4095 "\\`-?[ \t]*" "" delim))))))
3680 4096
4097(define-minor-mode sh-electric-here-document-mode
4098 "Make << insert a here document skeleton."
4099 nil nil nil
4100 (if sh-electric-here-document-mode
4101 (add-hook 'post-self-insert-hook #'sh--maybe-here-document nil t)
4102 (remove-hook 'post-self-insert-hook #'sh--maybe-here-document t)))
3681 4103
3682;; various other commands 4104;; various other commands
3683 4105
@@ -3696,12 +4118,14 @@ The document is bounded by `sh-here-document-word'."
3696 4118
3697 4119
3698(defun sh-beginning-of-command () 4120(defun sh-beginning-of-command ()
4121 ;; FIXME: Redefine using SMIE.
3699 "Move point to successive beginnings of commands." 4122 "Move point to successive beginnings of commands."
3700 (interactive) 4123 (interactive)
3701 (if (re-search-backward sh-beginning-of-command nil t) 4124 (if (re-search-backward sh-beginning-of-command nil t)
3702 (goto-char (match-beginning 2)))) 4125 (goto-char (match-beginning 2))))
3703 4126
3704(defun sh-end-of-command () 4127(defun sh-end-of-command ()
4128 ;; FIXME: Redefine using SMIE.
3705 "Move point to successive ends of commands." 4129 "Move point to successive ends of commands."
3706 (interactive) 4130 (interactive)
3707 (if (re-search-forward sh-end-of-command nil t) 4131 (if (re-search-forward sh-end-of-command nil t)
diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el
index 0139795dd38..0cd8d01aff1 100644
--- a/lisp/progmodes/verilog-mode.el
+++ b/lisp/progmodes/verilog-mode.el
@@ -123,9 +123,9 @@
123;;; Code: 123;;; Code:
124 124
125;; This variable will always hold the version number of the mode 125;; This variable will always hold the version number of the mode
126(defconst verilog-mode-version "725" 126(defconst verilog-mode-version "800"
127 "Version of this Verilog mode.") 127 "Version of this Verilog mode.")
128(defconst verilog-mode-release-date "2011-11-27-GNU" 128(defconst verilog-mode-release-date "2012-04-23-GNU"
129 "Release date of this Verilog mode.") 129 "Release date of this Verilog mode.")
130(defconst verilog-mode-release-emacs t 130(defconst verilog-mode-release-emacs t
131 "If non-nil, this version of Verilog mode was released with Emacs itself.") 131 "If non-nil, this version of Verilog mode was released with Emacs itself.")
@@ -393,7 +393,7 @@ Set `verilog-in-hooks' during this time, to assist AUTO caches."
393 (parse-partial-sexp (point-min) (or pos (point))))) 393 (parse-partial-sexp (point-min) (or pos (point)))))
394 394
395(defgroup verilog-mode nil 395(defgroup verilog-mode nil
396 "Facilitates easy editing of Verilog source text." 396 "Major mode for Verilog source code."
397 :version "22.2" 397 :version "22.2"
398 :group 'languages) 398 :group 'languages)
399 399
@@ -415,7 +415,10 @@ Set `verilog-in-hooks' during this time, to assist AUTO caches."
415 :group 'verilog-mode) 415 :group 'verilog-mode)
416 416
417(defvar verilog-debug nil 417(defvar verilog-debug nil
418 "If set, enable debug messages for `verilog-mode' internals.") 418 "Non-nil means enable debug messages for `verilog-mode' internals.")
419
420(defvar verilog-warn-fatal nil
421 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
419 422
420(defcustom verilog-linter 423(defcustom verilog-linter
421 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" 424 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
@@ -524,6 +527,8 @@ are lineup only when \\[verilog-pretty-declarations] is typed."
524 (const :tag "Line up Declarations" declarations) 527 (const :tag "Line up Declarations" declarations)
525 (function :tag "Other")) 528 (function :tag "Other"))
526 :group 'verilog-mode-indent ) 529 :group 'verilog-mode-indent )
530(put 'verilog-auto-lineup 'safe-local-variable
531 '(lambda (x) (memq x '(nil all assignments declarations))))
527 532
528(defcustom verilog-indent-level 3 533(defcustom verilog-indent-level 3
529 "Indentation of Verilog statements with respect to containing block." 534 "Indentation of Verilog statements with respect to containing block."
@@ -600,40 +605,39 @@ Set to 0 to have all directives start at the left side of the screen."
600(put 'verilog-case-indent 'safe-local-variable 'integerp) 605(put 'verilog-case-indent 'safe-local-variable 'integerp)
601 606
602(defcustom verilog-auto-newline t 607(defcustom verilog-auto-newline t
603 "True means automatically newline after semicolons." 608 "Non-nil means automatically newline after semicolons."
604 :group 'verilog-mode-indent 609 :group 'verilog-mode-indent
605 :type 'boolean) 610 :type 'boolean)
606(put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp) 611(put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
607 612
608(defcustom verilog-auto-indent-on-newline t 613(defcustom verilog-auto-indent-on-newline t
609 "True means automatically indent line after newline." 614 "Non-nil means automatically indent line after newline."
610 :group 'verilog-mode-indent 615 :group 'verilog-mode-indent
611 :type 'boolean) 616 :type 'boolean)
612(put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp) 617(put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
613 618
614(defcustom verilog-tab-always-indent t 619(defcustom verilog-tab-always-indent t
615 "True means TAB should always re-indent the current line. 620 "Non-nil means TAB should always re-indent the current line.
616A nil value means TAB will only reindent when at the beginning of the line." 621A nil value means TAB will only reindent when at the beginning of the line."
617 :group 'verilog-mode-indent 622 :group 'verilog-mode-indent
618 :type 'boolean) 623 :type 'boolean)
619(put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp) 624(put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
620 625
621(defcustom verilog-tab-to-comment nil 626(defcustom verilog-tab-to-comment nil
622 "True means TAB moves to the right hand column in preparation for a comment." 627 "Non-nil means TAB moves to the right hand column in preparation for a comment."
623 :group 'verilog-mode-actions 628 :group 'verilog-mode-actions
624 :type 'boolean) 629 :type 'boolean)
625(put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp) 630(put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
626 631
627(defcustom verilog-indent-begin-after-if t 632(defcustom verilog-indent-begin-after-if t
628 "If true, indent begin statements following if, else, while, for and repeat. 633 "Non-nil means indent begin statements following if, else, while, etc.
629Otherwise, line them up." 634Otherwise, line them up."
630 :group 'verilog-mode-indent 635 :group 'verilog-mode-indent
631 :type 'boolean) 636 :type 'boolean)
632(put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp) 637(put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
633 638
634
635(defcustom verilog-align-ifelse nil 639(defcustom verilog-align-ifelse nil
636 "If true, align `else' under matching `if'. 640 "Non-nil means align `else' under matching `if'.
637Otherwise else is lined up with first character on line holding matching if." 641Otherwise else is lined up with first character on line holding matching if."
638 :group 'verilog-mode-indent 642 :group 'verilog-mode-indent
639 :type 'boolean) 643 :type 'boolean)
@@ -648,7 +652,7 @@ default avoids too many redundant comments in tight quarters."
648(put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp) 652(put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
649 653
650(defcustom verilog-highlight-p1800-keywords nil 654(defcustom verilog-highlight-p1800-keywords nil
651 "True means highlight words newly reserved by IEEE-1800. 655 "Non-nil means highlight words newly reserved by IEEE-1800.
652These will appear in `verilog-font-lock-p1800-face' in order to gently 656These will appear in `verilog-font-lock-p1800-face' in order to gently
653suggest changing where these words are used as variables to something else. 657suggest changing where these words are used as variables to something else.
654A nil value means highlight these words as appropriate for the SystemVerilog 658A nil value means highlight these words as appropriate for the SystemVerilog
@@ -659,7 +663,7 @@ to see the effect as font color choices are cached by Emacs."
659(put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp) 663(put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
660 664
661(defcustom verilog-highlight-grouping-keywords nil 665(defcustom verilog-highlight-grouping-keywords nil
662 "True means highlight grouping keywords 'begin' and 'end' more dramatically. 666 "Non-nil means highlight grouping keywords 'begin' and 'end' more dramatically.
663If false, these words are in the `font-lock-type-face'; if True then they are in 667If false, these words are in the `font-lock-type-face'; if True then they are in
664`verilog-font-lock-ams-face'. Some find that special highlighting on these 668`verilog-font-lock-ams-face'. Some find that special highlighting on these
665grouping constructs allow the structure of the code to be understood at a glance." 669grouping constructs allow the structure of the code to be understood at a glance."
@@ -668,7 +672,7 @@ grouping constructs allow the structure of the code to be understood at a glance
668(put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp) 672(put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
669 673
670(defcustom verilog-highlight-modules nil 674(defcustom verilog-highlight-modules nil
671 "True means highlight module statements for `verilog-load-file-at-point'. 675 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
672When true, mousing over module names will allow jumping to the 676When true, mousing over module names will allow jumping to the
673module definition. If false, this is not supported. Setting 677module definition. If false, this is not supported. Setting
674this is experimental, and may lead to bad performance." 678this is experimental, and may lead to bad performance."
@@ -677,7 +681,7 @@ this is experimental, and may lead to bad performance."
677(put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp) 681(put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
678 682
679(defcustom verilog-highlight-includes t 683(defcustom verilog-highlight-includes t
680 "True means highlight module statements for `verilog-load-file-at-point'. 684 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
681When true, mousing over include file names will allow jumping to the 685When true, mousing over include file names will allow jumping to the
682file referenced. If false, this is not supported." 686file referenced. If false, this is not supported."
683 :group 'verilog-mode-indent 687 :group 'verilog-mode-indent
@@ -689,7 +693,7 @@ file referenced. If false, this is not supported."
689Set this to \"wire\" if the Verilog code uses \"`default_nettype 693Set this to \"wire\" if the Verilog code uses \"`default_nettype
690none\". Note using `default_nettype none isn't recommended practice; this 694none\". Note using `default_nettype none isn't recommended practice; this
691mode is experimental." 695mode is experimental."
692 :version "24.1" 696 :version "24.1" ;; rev670
693 :group 'verilog-mode-actions 697 :group 'verilog-mode-actions
694 :type 'boolean) 698 :type 'boolean)
695(put 'verilog-auto-declare-nettype 'safe-local-variable `stringp) 699(put 'verilog-auto-declare-nettype 'safe-local-variable `stringp)
@@ -697,27 +701,27 @@ mode is experimental."
697(defcustom verilog-auto-wire-type nil 701(defcustom verilog-auto-wire-type nil
698 "Non-nil specifies the data type to use with `verilog-auto-wire' etc. 702 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
699Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'." 703Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
700 :version "24.1" 704 :version "24.1" ;; rev673
701 :group 'verilog-mode-actions 705 :group 'verilog-mode-actions
702 :type 'boolean) 706 :type 'boolean)
703(put 'verilog-auto-wire-type 'safe-local-variable `stringp) 707(put 'verilog-auto-wire-type 'safe-local-variable `stringp)
704 708
705(defcustom verilog-auto-endcomments t 709(defcustom verilog-auto-endcomments t
706 "True means insert a comment /* ... */ after 'end's. 710 "Non-nil means insert a comment /* ... */ after 'end's.
707The name of the function or case will be set between the braces." 711The name of the function or case will be set between the braces."
708 :group 'verilog-mode-actions 712 :group 'verilog-mode-actions
709 :type 'boolean) 713 :type 'boolean)
710(put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp) 714(put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
711 715
712(defcustom verilog-auto-delete-trailing-whitespace nil 716(defcustom verilog-auto-delete-trailing-whitespace nil
713 "True means to `delete-trailing-whitespace' in `verilog-auto'." 717 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
714 :version "24.1" 718 :version "24.1" ;; rev703
715 :group 'verilog-mode-actions 719 :group 'verilog-mode-actions
716 :type 'boolean) 720 :type 'boolean)
717(put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp) 721(put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)
718 722
719(defcustom verilog-auto-ignore-concat nil 723(defcustom verilog-auto-ignore-concat nil
720 "True means ignore signals in {...} concatenations for AUTOWIRE etc. 724 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
721This will exclude signals referenced as pin connections in {...} 725This will exclude signals referenced as pin connections in {...}
722from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set 726from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
723for backward compatibility only and not set in new designs; it 727for backward compatibility only and not set in new designs; it
@@ -727,7 +731,7 @@ may be removed in future versions."
727(put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp) 731(put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)
728 732
729(defcustom verilog-auto-read-includes nil 733(defcustom verilog-auto-read-includes nil
730 "True means to automatically read includes before AUTOs. 734 "Non-nil means to automatically read includes before AUTOs.
731This will do a `verilog-read-defines' and `verilog-read-includes' before 735This will do a `verilog-read-defines' and `verilog-read-includes' before
732each AUTO expansion. This makes it easier to embed defines and includes, 736each AUTO expansion. This makes it easier to embed defines and includes,
733but can result in very slow reading times if there are many or large 737but can result in very slow reading times if there are many or large
@@ -750,15 +754,15 @@ sub-module's port list has changed."
750 :type '(choice (const nil) (const ask) (const detect) (const force))) 754 :type '(choice (const nil) (const ask) (const detect) (const force)))
751 755
752(defcustom verilog-auto-star-expand t 756(defcustom verilog-auto-star-expand t
753 "Non-nil indicates to expand a SystemVerilog .* instance ports. 757 "Non-nil means to expand SystemVerilog .* instance ports.
754They will be expanded in the same way as if there was a AUTOINST in the 758They will be expanded in the same way as if there was an AUTOINST in the
755instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'." 759instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
756 :group 'verilog-mode-actions 760 :group 'verilog-mode-actions
757 :type 'boolean) 761 :type 'boolean)
758(put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp) 762(put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
759 763
760(defcustom verilog-auto-star-save nil 764(defcustom verilog-auto-star-save nil
761 "Non-nil indicates to save to disk SystemVerilog .* instance expansions. 765 "Non-nil means save to disk SystemVerilog .* instance expansions.
762A nil value indicates direct connections will be removed before saving. 766A nil value indicates direct connections will be removed before saving.
763Only meaningful to those created due to `verilog-auto-star-expand' being set. 767Only meaningful to those created due to `verilog-auto-star-expand' being set.
764 768
@@ -964,7 +968,7 @@ you will probably also need `verilog-auto-reset-widths' set."
964(put 'verilog-active-low-regexp 'safe-local-variable 'stringp) 968(put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
965 969
966(defcustom verilog-auto-sense-include-inputs nil 970(defcustom verilog-auto-sense-include-inputs nil
967 "If true, AUTOSENSE should include all inputs. 971 "Non-nil means AUTOSENSE should include all inputs.
968If nil, only inputs that are NOT output signals in the same block are 972If nil, only inputs that are NOT output signals in the same block are
969included." 973included."
970 :group 'verilog-mode-auto 974 :group 'verilog-mode-auto
@@ -972,7 +976,7 @@ included."
972(put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp) 976(put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
973 977
974(defcustom verilog-auto-sense-defines-constant nil 978(defcustom verilog-auto-sense-defines-constant nil
975 "If true, AUTOSENSE should assume all defines represent constants. 979 "Non-nil means AUTOSENSE should assume all defines represent constants.
976When true, the defines will not be included in sensitivity lists. To 980When true, the defines will not be included in sensitivity lists. To
977maintain compatibility with other sites, this should be set at the bottom 981maintain compatibility with other sites, this should be set at the bottom
978of each Verilog file that requires it, rather than being set globally." 982of each Verilog file that requires it, rather than being set globally."
@@ -981,28 +985,36 @@ of each Verilog file that requires it, rather than being set globally."
981(put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp) 985(put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
982 986
983(defcustom verilog-auto-reset-blocking-in-non t 987(defcustom verilog-auto-reset-blocking-in-non t
984 "If true, AUTORESET will reset those signals which were 988 "Non-nil means AUTORESET will reset blocking statements.
985assigned with blocking assignments (=) even in a block with 989When true, AUTORESET will reset in blocking statements those
986non-blocking assignments (<=). 990signals which were assigned with blocking assignments (=) even in
991a block with non-blocking assignments (<=).
987 992
988If nil, all blocking assigned signals are ignored when any 993If nil, all blocking assigned signals are ignored when any
989non-blocking assignment is in the AUTORESET block. This allows 994non-blocking assignment is in the AUTORESET block. This allows
990blocking assignments to be used for temporary values and not have 995blocking assignments to be used for temporary values and not have
991those temporaries reset. See example in `verilog-auto-reset'." 996those temporaries reset. See example in `verilog-auto-reset'."
992 :version "24.1" 997 :version "24.1" ;; rev718
993 :type 'boolean 998 :type 'boolean
994 :group 'verilog-mode-auto) 999 :group 'verilog-mode-auto)
995(put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp) 1000(put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)
996 1001
997(defcustom verilog-auto-reset-widths t 1002(defcustom verilog-auto-reset-widths t
998 "If true, AUTORESET should determine the width of signals. 1003 "True means AUTORESET should determine the width of signals.
999This is then used to set the width of the zero (32'h0 for example). This 1004This is then used to set the width of the zero (32'h0 for example). This
1000is required by some lint tools that aren't smart enough to ignore widths of 1005is required by some lint tools that aren't smart enough to ignore widths of
1001the constant zero. This may result in ugly code when parameters determine 1006the constant zero. This may result in ugly code when parameters determine
1002the MSB or LSB of a signal inside an AUTORESET." 1007the MSB or LSB of a signal inside an AUTORESET.
1008
1009If nil, AUTORESET uses \"0\" as the constant.
1010
1011If 'unbased', AUTORESET used the unbased unsized literal \"'0\"
1012as the constant. This setting is strongly recommended for
1013SystemVerilog designs."
1003 :type 'boolean 1014 :type 'boolean
1004 :group 'verilog-mode-auto) 1015 :group 'verilog-mode-auto)
1005(put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp) 1016(put 'verilog-auto-reset-widths 'safe-local-variable
1017 '(lambda (x) (memq x '(nil t unbased))))
1006 1018
1007(defcustom verilog-assignment-delay "" 1019(defcustom verilog-assignment-delay ""
1008 "Text used for delays in delayed assignments. Add a trailing space if set." 1020 "Text used for delays in delayed assignments. Add a trailing space if set."
@@ -1011,7 +1023,7 @@ the MSB or LSB of a signal inside an AUTORESET."
1011(put 'verilog-assignment-delay 'safe-local-variable 'stringp) 1023(put 'verilog-assignment-delay 'safe-local-variable 'stringp)
1012 1024
1013(defcustom verilog-auto-arg-sort nil 1025(defcustom verilog-auto-arg-sort nil
1014 "If set, AUTOARG signal names will be sorted, not in declaration order. 1026 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1015Declaration order is advantageous with order based instantiations 1027Declaration order is advantageous with order based instantiations
1016and is the default for backward compatibility. Sorted order 1028and is the default for backward compatibility. Sorted order
1017reduces changes when declarations are moved around in a file, and 1029reduces changes when declarations are moved around in a file, and
@@ -1023,7 +1035,7 @@ See also `verilog-auto-inst-sort'."
1023(put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp) 1035(put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
1024 1036
1025(defcustom verilog-auto-inst-dot-name nil 1037(defcustom verilog-auto-inst-dot-name nil
1026 "If true, when creating ports with AUTOINST, use .name syntax. 1038 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1027This will use \".port\" instead of \".port(port)\" when possible. 1039This will use \".port\" instead of \".port(port)\" when possible.
1028This is only legal in SystemVerilog files, and will confuse older 1040This is only legal in SystemVerilog files, and will confuse older
1029simulators. Setting `verilog-auto-inst-vector' to nil may also 1041simulators. Setting `verilog-auto-inst-vector' to nil may also
@@ -1033,7 +1045,7 @@ be desirable to increase how often .name will be used."
1033(put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp) 1045(put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
1034 1046
1035(defcustom verilog-auto-inst-param-value nil 1047(defcustom verilog-auto-inst-param-value nil
1036 "If set, AUTOINST will replace parameters with the parameter value. 1048 "Non-nil means AUTOINST will replace parameters with the parameter value.
1037If nil, leave parameters as symbolic names. 1049If nil, leave parameters as symbolic names.
1038 1050
1039Parameters must be in Verilog 2001 format #(...), and if a parameter is not 1051Parameters must be in Verilog 2001 format #(...), and if a parameter is not
@@ -1041,7 +1053,7 @@ listed as such there (as when the default value is acceptable), it will not
1041be replaced, and will remain symbolic. 1053be replaced, and will remain symbolic.
1042 1054
1043For example, imagine a submodule uses parameters to declare the size of its 1055For example, imagine a submodule uses parameters to declare the size of its
1044inputs. This is then used by a upper module: 1056inputs. This is then used by an upper module:
1045 1057
1046 module InstModule (o,i); 1058 module InstModule (o,i);
1047 parameter WIDTH; 1059 parameter WIDTH;
@@ -1070,20 +1082,20 @@ instead expand to:
1070(put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp) 1082(put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
1071 1083
1072(defcustom verilog-auto-inst-sort nil 1084(defcustom verilog-auto-inst-sort nil
1073 "If set, AUTOINST signal names will be sorted, not in declaration order. 1085 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1074Also affects AUTOINSTPARAM. Declaration order is the default for 1086Also affects AUTOINSTPARAM. Declaration order is the default for
1075backward compatibility, and as some teams prefer signals that are 1087backward compatibility, and as some teams prefer signals that are
1076declared together to remain together. Sorted order reduces 1088declared together to remain together. Sorted order reduces
1077changes when declarations are moved around in a file. 1089changes when declarations are moved around in a file.
1078 1090
1079See also `verilog-auto-arg-sort'." 1091See also `verilog-auto-arg-sort'."
1080 :version "24.1" 1092 :version "24.1" ;; rev688
1081 :group 'verilog-mode-auto 1093 :group 'verilog-mode-auto
1082 :type 'boolean) 1094 :type 'boolean)
1083(put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp) 1095(put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)
1084 1096
1085(defcustom verilog-auto-inst-vector t 1097(defcustom verilog-auto-inst-vector t
1086 "If true, when creating default ports with AUTOINST, use bus subscripts. 1098 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1087If nil, skip the subscript when it matches the entire bus as declared in 1099If nil, skip the subscript when it matches the entire bus as declared in
1088the module (AUTOWIRE signals always are subscripted, you must manually 1100the module (AUTOWIRE signals always are subscripted, you must manually
1089declare the wire to have the subscripts removed.) Setting this to nil may 1101declare the wire to have the subscripts removed.) Setting this to nil may
@@ -1115,6 +1127,12 @@ won't merge conflict."
1115 :type 'integer) 1127 :type 'integer)
1116(put 'verilog-auto-inst-column 'safe-local-variable 'integerp) 1128(put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
1117 1129
1130(defcustom verilog-auto-inst-interfaced-ports t
1131 "Non-nil means include interfaced ports in AUTOINST expansions."
1132 :group 'verilog-mode-auto
1133 :type 'boolean)
1134(put 'verilog-auto-inst-interfaced-ports 'safe-local-variable 'verilog-booleanp)
1135
1118(defcustom verilog-auto-input-ignore-regexp nil 1136(defcustom verilog-auto-input-ignore-regexp nil
1119 "If set, when creating AUTOINPUT list, ignore signals matching this regexp. 1137 "If set, when creating AUTOINPUT list, ignore signals matching this regexp.
1120See the \\[verilog-faq] for examples on using this." 1138See the \\[verilog-faq] for examples on using this."
@@ -1136,11 +1154,18 @@ See the \\[verilog-faq] for examples on using this."
1136 :type 'string) 1154 :type 'string)
1137(put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp) 1155(put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
1138 1156
1157(defcustom verilog-auto-template-warn-unused nil
1158 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1159This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1160 :group 'verilog-mode-auto
1161 :type 'boolean)
1162(put 'verilog-auto-template-warn-unused 'safe-local-variable 'verilog-booleanp)
1163
1139(defcustom verilog-auto-tieoff-declaration "wire" 1164(defcustom verilog-auto-tieoff-declaration "wire"
1140 "Data type used for the declaration for AUTOTIEOFF. If \"wire\" then 1165 "Data type used for the declaration for AUTOTIEOFF.
1141create a wire, if \"assign\" create an assignment, else the data type for 1166If \"wire\" then create a wire, if \"assign\" create an
1142variable creation." 1167assignment, else the data type for variable creation."
1143 :version "24.1" 1168 :version "24.1" ;; rev713
1144 :group 'verilog-mode-auto 1169 :group 'verilog-mode-auto
1145 :type 'string) 1170 :type 'string)
1146(put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp) 1171(put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
@@ -1201,6 +1226,16 @@ For example, \"_t$\" matches typedefs named with _t, as in the C language."
1201 :group 'verilog-mode-auto 1226 :group 'verilog-mode-auto
1202 :type 'hook) 1227 :type 'hook)
1203 1228
1229(defcustom verilog-before-save-font-hook nil
1230 "Hook run before `verilog-save-font-mods' removes highlighting."
1231 :group 'verilog-mode-auto
1232 :type 'hook)
1233
1234(defcustom verilog-after-save-font-hook nil
1235 "Hook run after `verilog-save-font-mods' restores highlighting."
1236 :group 'verilog-mode-auto
1237 :type 'hook)
1238
1204(defvar verilog-imenu-generic-expression 1239(defvar verilog-imenu-generic-expression
1205 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4) 1240 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
1206 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)) 1241 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
@@ -1430,6 +1465,8 @@ If set will become buffer local.")
1430 :help "Help on AUTOSENSE - sensitivity lists for always blocks"] 1465 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1431 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff) 1466 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1432 :help "Help on AUTOTIEOFF - tying off unused outputs"] 1467 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1468 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1469 :help "Help on AUTOUNDEF - undefine all local defines"]
1433 ["AUTOUNUSED" (describe-function 'verilog-auto-unused) 1470 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1434 :help "Help on AUTOUNUSED - terminating unused inputs"] 1471 :help "Help on AUTOUNUSED - terminating unused inputs"]
1435 ["AUTOWIRE" (describe-function 'verilog-auto-wire) 1472 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
@@ -1552,7 +1589,7 @@ If set will become buffer local.")
1552FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace. 1589FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1553The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\") 1590The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1554will break, as the o's continuously replace. xa -> x works ok though." 1591will break, as the o's continuously replace. xa -> x works ok though."
1555 ;; Hopefully soon to a emacs built-in 1592 ;; Hopefully soon to an Emacs built-in
1556 ;; Also note \ in the replacement prevent multiple replacements; IE 1593 ;; Also note \ in the replacement prevent multiple replacements; IE
1557 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@") 1594 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1558 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)" 1595 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
@@ -2401,7 +2438,6 @@ find the errors."
2401 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28 2438 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;28
2402 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)" 2439 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2403 ;; 2440 ;;
2404
2405 )) 2441 ))
2406 2442
2407(defconst verilog-end-block-ordered-rry 2443(defconst verilog-end-block-ordered-rry
@@ -2629,11 +2665,11 @@ find the errors."
2629 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" 2665 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2630 )))) 2666 ))))
2631(defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>") 2667(defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2632(defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") 2668(defconst verilog-extended-case-re "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
2633(defconst verilog-extended-complete-re 2669(defconst verilog-extended-complete-re
2634 (concat "\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" 2670 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<pure\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2635 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" 2671 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2636 "\\|\\(\\<import\\>\\s-+\\)?\"DPI-C\"\\s-+\\(function\\>\\|task\\>\\)" 2672 "\\|\\(\\(\\<import\\>\\s-+\\)?\\(\"DPI-C\"\\s-+\\)?\\(\\<pure\\>\\s-+\\)?\\(function\\>\\|task\\>\\)\\)"
2637 "\\|" verilog-extended-case-re )) 2673 "\\|" verilog-extended-case-re ))
2638(defconst verilog-basic-complete-re 2674(defconst verilog-basic-complete-re
2639 (eval-when-compile 2675 (eval-when-compile
@@ -2645,9 +2681,7 @@ find the errors."
2645 )))) 2681 ))))
2646(defconst verilog-complete-reg 2682(defconst verilog-complete-reg
2647 (concat 2683 (concat
2648 verilog-extended-complete-re 2684 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2649 "\\|"
2650 verilog-basic-complete-re))
2651 2685
2652(defconst verilog-end-statement-re 2686(defconst verilog-end-statement-re
2653 (concat "\\(" verilog-beg-block-re "\\)\\|\\(" 2687 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
@@ -2764,7 +2798,8 @@ See also `verilog-font-lock-extra-types'.")
2764(defvar verilog-font-lock-keywords-3 nil 2798(defvar verilog-font-lock-keywords-3 nil
2765 "Gaudy level highlighting for Verilog mode. 2799 "Gaudy level highlighting for Verilog mode.
2766See also `verilog-font-lock-extra-types'.") 2800See also `verilog-font-lock-extra-types'.")
2767(defvar verilog-font-lock-translate-off-face 2801
2802(defvar verilog-font-lock-translate-off-face
2768 'verilog-font-lock-translate-off-face 2803 'verilog-font-lock-translate-off-face
2769 "Font to use for translated off regions.") 2804 "Font to use for translated off regions.")
2770(defface verilog-font-lock-translate-off-face 2805(defface verilog-font-lock-translate-off-face
@@ -2842,8 +2877,8 @@ See also `verilog-font-lock-extra-types'.")
2842 (verilog-pragma-keywords 2877 (verilog-pragma-keywords
2843 (eval-when-compile 2878 (eval-when-compile
2844 (verilog-regexp-opt 2879 (verilog-regexp-opt
2845 '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil 2880 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
2846 ))) 2881 ) nil )))
2847 2882
2848 (verilog-1800-2005-keywords 2883 (verilog-1800-2005-keywords
2849 (eval-when-compile 2884 (eval-when-compile
@@ -2968,7 +3003,7 @@ See also `verilog-font-lock-extra-types'.")
2968 (append verilog-font-lock-keywords-1 3003 (append verilog-font-lock-keywords-1
2969 (list 3004 (list
2970 ;; Fontify pragmas 3005 ;; Fontify pragmas
2971 (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)") 3006 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
2972 ;; Fontify escaped names 3007 ;; Fontify escaped names
2973 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face) 3008 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
2974 ;; Fontify macro definitions/ uses 3009 ;; Fontify macro definitions/ uses
@@ -3030,6 +3065,31 @@ For insignificant changes, see instead `verilog-save-buffer-state'."
3030 after-change-functions) 3065 after-change-functions)
3031 (progn ,@body))) 3066 (progn ,@body)))
3032 3067
3068(defvar verilog-save-font-mod-hooked nil
3069 "Local variable when inside a `verilog-save-font-mods' block.")
3070(make-variable-buffer-local 'verilog-save-font-mod-hooked)
3071
3072(defmacro verilog-save-font-mods (&rest body)
3073 "Execute BODY forms, disabling text modifications to allow performing BODY.
3074Includes temporary disabling of `font-lock' to restore the buffer
3075to full text form for parsing. Additional actions may be specified with
3076`verilog-before-save-font-hook' and `verilog-after-save-font-hook'."
3077 ;; Before version 20, match-string with font-lock returns a
3078 ;; vector that is not equal to the string. IE if on "input"
3079 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3080 `(let* ((hooked (unless verilog-save-font-mod-hooked
3081 (verilog-run-hooks 'verilog-before-save-font-hook)
3082 t))
3083 (verilog-save-font-mod-hooked t)
3084 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3085 (font-lock-mode 0)
3086 t)))
3087 (unwind-protect
3088 (progn ,@body)
3089 ;; Unwind forms
3090 (when fontlocked (font-lock-mode t))
3091 (when hooked (verilog-run-hooks 'verilog-after-save-font-hook)))))
3092
3033;; 3093;;
3034;; Comment detection and caching 3094;; Comment detection and caching
3035 3095
@@ -3161,7 +3221,7 @@ to establish comment properties on all text."
3161 3221
3162(defun verilog-insert (&rest stuff) 3222(defun verilog-insert (&rest stuff)
3163 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'. 3223 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3164Any insert that includes a comment must have the entire commente 3224Any insert that includes a comment must have the entire comment
3165inserted using a single call to `verilog-insert'." 3225inserted using a single call to `verilog-insert'."
3166 (let ((pt (point))) 3226 (let ((pt (point)))
3167 (while stuff 3227 (while stuff
@@ -3565,9 +3625,10 @@ Key bindings specific to `verilog-mode-map' are:
3565 3625
3566 ;; Stuff for GNU Emacs 3626 ;; Stuff for GNU Emacs
3567 (set (make-local-variable 'font-lock-defaults) 3627 (set (make-local-variable 'font-lock-defaults)
3568 `((verilog-font-lock-keywords verilog-font-lock-keywords-1 3628 `((verilog-font-lock-keywords
3569 verilog-font-lock-keywords-2 3629 verilog-font-lock-keywords-1
3570 verilog-font-lock-keywords-3) 3630 verilog-font-lock-keywords-2
3631 verilog-font-lock-keywords-3)
3571 nil nil nil 3632 nil nil nil
3572 ,(if (functionp 'syntax-ppss) 3633 ,(if (functionp 'syntax-ppss)
3573 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses 3634 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
@@ -4049,7 +4110,7 @@ With ARG, first kill any existing labels."
4049 (if (looking-at verilog-label-re) 4110 (if (looking-at verilog-label-re)
4050 (setq h (point)))) 4111 (setq h (point))))
4051 (goto-char h))) 4112 (goto-char h)))
4052 ;; stop if we see a complete reg, perhaps an extended one 4113 ;; stop if we see an extended complete reg, perhaps a complete one
4053 (and 4114 (and
4054 (looking-at verilog-complete-reg) 4115 (looking-at verilog-complete-reg)
4055 (let* ((p (point))) 4116 (let* ((p (point)))
@@ -4186,32 +4247,20 @@ More specifically, point @ in the line foo : @ begin"
4186 nil))) 4247 nil)))
4187 4248
4188(defun verilog-backward-up-list (arg) 4249(defun verilog-backward-up-list (arg)
4189 "Like `backward-up-list', but deal with comments." 4250 "Call `backward-up-list' ARG, ignoring comments."
4190 (let ((parse-sexp-ignore-comments t)) 4251 (let ((parse-sexp-ignore-comments t))
4191 (backward-up-list arg))) 4252 (backward-up-list arg)))
4192 4253
4193(defun verilog-forward-sexp-cmt (arg) 4254(defun verilog-forward-sexp-cmt (arg)
4194 "Call `forward-sexp', inside comments." 4255 "Call `forward-sexp' ARG, inside comments."
4195 (let ((parse-sexp-ignore-comments nil)) 4256 (let ((parse-sexp-ignore-comments nil))
4196 (forward-sexp arg))) 4257 (forward-sexp arg)))
4197 4258
4198(defun verilog-forward-sexp-ign-cmt (arg) 4259(defun verilog-forward-sexp-ign-cmt (arg)
4199 "Call `forward-sexp', ignoring comments." 4260 "Call `forward-sexp' ARG, ignoring comments."
4200 (let ((parse-sexp-ignore-comments t)) 4261 (let ((parse-sexp-ignore-comments t))
4201 (forward-sexp arg))) 4262 (forward-sexp arg)))
4202 4263
4203(defun verilog-in-struct-region-p ()
4204 "Return true if in a struct region.
4205More specifically, in a list after a struct|union keyword."
4206 (interactive)
4207 (save-excursion
4208 (let* ((state (verilog-syntax-ppss))
4209 (depth (nth 0 state)))
4210 (if depth
4211 (progn (verilog-backward-up-list depth)
4212 (verilog-beg-of-statement)
4213 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>"))))))
4214
4215(defun verilog-in-generate-region-p () 4264(defun verilog-in-generate-region-p ()
4216 "Return true if in a generate region. 4265 "Return true if in a generate region.
4217More specifically, after a generate and before an endgenerate." 4266More specifically, after a generate and before an endgenerate."
@@ -4658,10 +4707,10 @@ primitive or interface named NAME."
4658 (cond 4707 (cond
4659 ((match-end 5) ;; of verilog-end-block-ordered-re 4708 ((match-end 5) ;; of verilog-end-block-ordered-re
4660 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)") 4709 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4661 (setq name-re "\\w+\\s-*(") 4710 (setq name-re "\\w+\\s-*("))
4662 )
4663 ((match-end 6) ;; of verilog-end-block-ordered-re 4711 ((match-end 6) ;; of verilog-end-block-ordered-re
4664 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")) 4712 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
4713 (setq name-re "\\w+\\s-*("))
4665 ((match-end 7) ;; of verilog-end-block-ordered-re 4714 ((match-end 7) ;; of verilog-end-block-ordered-re
4666 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>")) 4715 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
4667 ((match-end 8) ;; of verilog-end-block-ordered-re 4716 ((match-end 8) ;; of verilog-end-block-ordered-re
@@ -4977,25 +5026,24 @@ becomes:
4977 (compile compile-command)) 5026 (compile compile-command))
4978 5027
4979(defun verilog-preprocess (&optional command filename) 5028(defun verilog-preprocess (&optional command filename)
4980 "Preprocess the buffer, similar to `compile', but leave output in Verilog-Mode. 5029 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
4981Takes optional COMMAND or defaults to `verilog-preprocessor', and 5030Takes optional COMMAND or defaults to `verilog-preprocessor', and
4982FILENAME or defaults to `buffer-file-name`." 5031FILENAME to find directory to run in, or defaults to `buffer-file-name`."
4983 (interactive 5032 (interactive
4984 (list 5033 (list
4985 (let ((default (verilog-expand-command verilog-preprocessor))) 5034 (let ((default (verilog-expand-command verilog-preprocessor)))
4986 (set (make-local-variable `verilog-preprocessor) 5035 (set (make-local-variable `verilog-preprocessor)
4987 (read-from-minibuffer "Run Preprocessor (like this): " 5036 (read-from-minibuffer "Run Preprocessor (like this): "
4988 default nil nil 5037 default nil nil
4989 'verilog-preprocess-history default))))) 5038 'verilog-preprocess-history default)))))
4990 (unless command (setq command (verilog-expand-command verilog-preprocessor))) 5039 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
4991 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode)) 5040 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
4992 (dir (file-name-directory (or filename buffer-file-name))) 5041 (dir (file-name-directory (or filename buffer-file-name)))
4993 (file (file-name-nondirectory (or filename buffer-file-name))) 5042 (cmd (concat "cd " dir "; " command)))
4994 (cmd (concat "cd " dir "; " command " " file)))
4995 (with-output-to-temp-buffer "*Verilog-Preprocessed*" 5043 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
4996 (with-current-buffer (get-buffer "*Verilog-Preprocessed*") 5044 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
4997 (insert (concat "// " cmd "\n")) 5045 (insert (concat "// " cmd "\n"))
4998 (shell-command cmd "*Verilog-Preprocessed*") 5046 (call-process shell-file-name nil t nil shell-command-switch cmd)
4999 (verilog-mode) 5047 (verilog-mode)
5000 ;; Without this force, it takes a few idle seconds 5048 ;; Without this force, it takes a few idle seconds
5001 ;; to get the color, which is very jarring 5049 ;; to get the color, which is very jarring
@@ -5006,17 +5054,30 @@ FILENAME or defaults to `buffer-file-name`."
5006;; Batch 5054;; Batch
5007;; 5055;;
5008 5056
5057(defun verilog-warn (string &rest args)
5058 "Print a warning with `format' using STRING and optional ARGS."
5059 (apply 'message (concat "%%Warning: " string) args))
5060
5061(defun verilog-warn-error (string &rest args)
5062 "Call `error' using STRING and optional ARGS.
5063If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5064 (if verilog-warn-fatal
5065 (apply 'error string args)
5066 (apply 'verilog-warn string args)))
5067
5009(defmacro verilog-batch-error-wrapper (&rest body) 5068(defmacro verilog-batch-error-wrapper (&rest body)
5010 "Execute BODY and add error prefix to any errors found. 5069 "Execute BODY and add error prefix to any errors found.
5011This lets programs calling batch mode to easily extract error messages." 5070This lets programs calling batch mode to easily extract error messages."
5012 `(condition-case err 5071 `(let ((verilog-warn-fatal nil))
5013 (progn ,@body) 5072 (condition-case err
5014 (error 5073 (progn ,@body)
5015 (error "%%Error: %s%s" (error-message-string err) 5074 (error
5016 (if (featurep 'xemacs) "\n" ""))))) ;; XEmacs forgets to add a newline 5075 (error "%%Error: %s%s" (error-message-string err)
5076 (if (featurep 'xemacs) "\n" "")))))) ;; XEmacs forgets to add a newline
5017 5077
5018(defun verilog-batch-execute-func (funref &optional no-save) 5078(defun verilog-batch-execute-func (funref &optional no-save)
5019 "Internal processing of a batch command, running FUNREF on all command arguments. 5079 "Internal processing of a batch command.
5080Runs FUNREF on all command arguments.
5020Save the result unless optional NO-SAVE is t." 5081Save the result unless optional NO-SAVE is t."
5021 (verilog-batch-error-wrapper 5082 (verilog-batch-error-wrapper
5022 ;; Setting global variables like that is *VERY NASTY* !!! --Stef 5083 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
@@ -5088,7 +5149,7 @@ line in bottom-up order."
5088 (verilog-batch-execute-func `verilog-inject-auto)) 5149 (verilog-batch-execute-func `verilog-inject-auto))
5089 5150
5090(defun verilog-batch-indent () 5151(defun verilog-batch-indent ()
5091 "For use with --batch, reindent an a entire file as a stand-alone tool. 5152 "For use with --batch, reindent an entire file as a stand-alone tool.
5092This sets up the appropriate Verilog mode environment, calls 5153This sets up the appropriate Verilog mode environment, calls
5093\\[verilog-indent-buffer] on all command-line files, and saves the buffers." 5154\\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5094 (unless noninteractive 5155 (unless noninteractive
@@ -5219,7 +5280,7 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5219 (verilog-beg-of-statement) ;; doesn't get to beginning 5280 (verilog-beg-of-statement) ;; doesn't get to beginning
5220 (if (looking-at verilog-property-re) 5281 (if (looking-at verilog-property-re)
5221 (throw 'nesting 'statement) ; We don't need an endproperty for these 5282 (throw 'nesting 'statement) ; We don't need an endproperty for these
5222 (throw 'nesting 'block) ;We still need a endproperty 5283 (throw 'nesting 'block) ;We still need an endproperty
5223 )) 5284 ))
5224 (t ; endblock 5285 (t ; endblock
5225 ; try to leap back to matching outward block by striding across 5286 ; try to leap back to matching outward block by striding across
@@ -5312,7 +5373,6 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5312 (t 5373 (t
5313 (setq depth (verilog-current-indent-level))))) 5374 (setq depth (verilog-current-indent-level)))))
5314 (message "You are at nesting %s depth %d" type depth)))) 5375 (message "You are at nesting %s depth %d" type depth))))
5315
5316(defun verilog-calc-1 () 5376(defun verilog-calc-1 ()
5317 (catch 'nesting 5377 (catch 'nesting
5318 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))) 5378 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
@@ -5370,9 +5430,10 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5370 ; endfunction 5430 ; endfunction
5371 (verilog-beg-of-statement) 5431 (verilog-beg-of-statement)
5372 (if (looking-at verilog-beg-block-re-ordered) 5432 (if (looking-at verilog-beg-block-re-ordered)
5373 (throw 'nesting 'block) 5433 (throw 'nesting 'block)
5374 (throw 'nesting 'defun))) 5434 (throw 'nesting 'defun)))
5375 5435
5436 ;;
5376 ((looking-at "\\<property\\>") 5437 ((looking-at "\\<property\\>")
5377 ; *sigh* 5438 ; *sigh*
5378 ; {assert|assume|cover} property (); are complete 5439 ; {assert|assume|cover} property (); are complete
@@ -5382,7 +5443,7 @@ Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5382 (verilog-beg-of-statement) 5443 (verilog-beg-of-statement)
5383 (if (looking-at verilog-property-re) 5444 (if (looking-at verilog-property-re)
5384 (throw 'continue 'statement) ; We don't need an endproperty for these 5445 (throw 'continue 'statement) ; We don't need an endproperty for these
5385 (throw 'nesting 'block) ;We still need a endproperty 5446 (throw 'nesting 'block) ;We still need an endproperty
5386 )) 5447 ))
5387 5448
5388 (t (throw 'nesting 'block)))) 5449 (t (throw 'nesting 'block))))
@@ -5715,7 +5776,7 @@ Set point to where line starts."
5715 (forward-comment (- (buffer-size)))) 5776 (forward-comment (- (buffer-size))))
5716 5777
5717(defun verilog-backward-syntactic-ws-quick () 5778(defun verilog-backward-syntactic-ws-quick ()
5718 "As with `verilog-backward-syntactic-ws' but uses `verilog-scan' cache." 5779 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
5719 (while (cond ((bobp) 5780 (while (cond ((bobp)
5720 nil) ; Done 5781 nil) ; Done
5721 ((> (skip-syntax-backward " ") 0) 5782 ((> (skip-syntax-backward " ") 0)
@@ -5864,7 +5925,7 @@ May cache result using `verilog-syntax-ppss'."
5864 5925
5865(defun verilog-in-paren-quick () 5926(defun verilog-in-paren-quick ()
5866 "Return true if in a parenthetical expression. 5927 "Return true if in a parenthetical expression.
5867Always starts from point-min, to allow inserts with hooks disabled." 5928Always starts from `point-min', to allow inserts with hooks disabled."
5868 ;; The -quick refers to its use alongside the other -quick functions, 5929 ;; The -quick refers to its use alongside the other -quick functions,
5869 ;; not that it's likely to be faster than verilog-in-paren. 5930 ;; not that it's likely to be faster than verilog-in-paren.
5870 (let ((state (save-excursion (parse-partial-sexp (point-min) (point))))) 5931 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
@@ -6118,7 +6179,7 @@ Only look at a few lines to determine indent level."
6118 (indent-line-to val) 6179 (indent-line-to val)
6119 (if (and (not verilog-indent-lists) 6180 (if (and (not verilog-indent-lists)
6120 (verilog-in-paren)) 6181 (verilog-in-paren))
6121 (verilog-pretty-declarations)) 6182 (verilog-pretty-declarations-auto))
6122 )) 6183 ))
6123 ((= (preceding-char) ?\) ) 6184 ((= (preceding-char) ?\) )
6124 (goto-char here) 6185 (goto-char here)
@@ -6154,7 +6215,7 @@ Only look at a few lines to determine indent level."
6154 (looking-at verilog-declaration-re)))) 6215 (looking-at verilog-declaration-re))))
6155 (indent-line-to val) 6216 (indent-line-to val)
6156 (if decl 6217 (if decl
6157 (verilog-pretty-declarations)))) 6218 (verilog-pretty-declarations-auto))))
6158 6219
6159 (;-- Handle the ends 6220 (;-- Handle the ends
6160 (or 6221 (or
@@ -6285,6 +6346,12 @@ ARG is ignored, for `comment-indent-function' compatibility."
6285 6346
6286;; 6347;;
6287 6348
6349(defun verilog-pretty-declarations-auto (&optional quiet)
6350 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6351 (when (or (eq 'all verilog-auto-lineup)
6352 (eq 'declarations verilog-auto-lineup))
6353 (verilog-pretty-declarations quiet)))
6354
6288(defun verilog-pretty-declarations (&optional quiet) 6355(defun verilog-pretty-declarations (&optional quiet)
6289 "Line up declarations around point. 6356 "Line up declarations around point.
6290Be verbose about progress unless optional QUIET set." 6357Be verbose about progress unless optional QUIET set."
@@ -6431,100 +6498,101 @@ Be verbose about progress unless optional QUIET set."
6431 (interactive) 6498 (interactive)
6432 (if (not (verilog-in-comment-or-string-p)) 6499 (if (not (verilog-in-comment-or-string-p))
6433 (save-excursion 6500 (save-excursion
6434 (let ((rexp (concat "^\\s-*" verilog-complete-reg))) 6501 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6435 (beginning-of-line) 6502 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6436 (if (and (not (looking-at rexp )) 6503 (beginning-of-line)
6437 (looking-at verilog-assignment-operation-re) 6504 (if (and (not (looking-at rexp ))
6438 (save-excursion 6505 (looking-at verilog-assignment-operation-re)
6439 (goto-char (match-end 2)) 6506 (save-excursion
6440 (and (not (verilog-in-attribute-p)) 6507 (goto-char (match-end 2))
6441 (not (verilog-in-parameter-p)) 6508 (and (not (verilog-in-attribute-p))
6442 (not (verilog-in-comment-or-string-p))))) 6509 (not (verilog-in-parameter-p))
6443 (let* ((here (point)) 6510 (not (verilog-in-comment-or-string-p)))))
6444 (e) (r) 6511 (let* ((here (point))
6445 (start 6512 (e) (r)
6446 (progn 6513 (start
6447 (beginning-of-line) 6514 (progn
6448 (setq e (point)) 6515 (beginning-of-line)
6449 (verilog-backward-syntactic-ws) 6516 (setq e (point))
6450 (beginning-of-line) 6517 (verilog-backward-syntactic-ws)
6451 (while (and (not (looking-at rexp )) 6518 (beginning-of-line)
6452 (looking-at verilog-assignment-operation-re) 6519 (while (and (not (looking-at rexp1))
6453 (not (bobp)) 6520 (looking-at verilog-assignment-operation-re)
6454 ) 6521 (not (bobp))
6455 (setq e (point)) 6522 )
6456 (verilog-backward-syntactic-ws) 6523 (setq e (point))
6457 (beginning-of-line) 6524 (verilog-backward-syntactic-ws)
6458 ) ;Ack, need to grok `define 6525 (beginning-of-line)
6459 e)) 6526 ) ;Ack, need to grok `define
6460 (end 6527 e))
6461 (progn 6528 (end
6462 (goto-char here) 6529 (progn
6463 (end-of-line) 6530 (goto-char here)
6464 (setq e (point)) ;Might be on last line 6531 (end-of-line)
6465 (verilog-forward-syntactic-ws) 6532 (setq e (point)) ;Might be on last line
6466 (beginning-of-line) 6533 (verilog-forward-syntactic-ws)
6467 (while (and 6534 (beginning-of-line)
6468 (not (looking-at rexp )) 6535 (while (and
6469 (looking-at verilog-assignment-operation-re) 6536 (not (looking-at rexp1 ))
6470 (progn 6537 (looking-at verilog-assignment-operation-re)
6471 (end-of-line) 6538 (progn
6472 (not (eq e (point))))) 6539 (end-of-line)
6473 (setq e (point)) 6540 (not (eq e (point)))))
6474 (verilog-forward-syntactic-ws) 6541 (setq e (point))
6475 (beginning-of-line) 6542 (verilog-forward-syntactic-ws)
6476 ) 6543 (beginning-of-line)
6477 e)) 6544 )
6478 (endpos (set-marker (make-marker) end)) 6545 e))
6479 (ind) 6546 (endpos (set-marker (make-marker) end))
6480 ) 6547 (ind)
6481 (goto-char start) 6548 )
6482 (verilog-do-indent (verilog-calculate-indent)) 6549 (goto-char start)
6483 (if (and (not quiet) 6550 (verilog-do-indent (verilog-calculate-indent))
6484 (> (- end start) 100)) 6551 (if (and (not quiet)
6485 (message "Lining up expressions..(please stand by)")) 6552 (> (- end start) 100))
6486 6553 (message "Lining up expressions..(please stand by)"))
6487 ;; Set indent to minimum throughout region 6554
6488 (while (< (point) (marker-position endpos)) 6555 ;; Set indent to minimum throughout region
6489 (beginning-of-line) 6556 (while (< (point) (marker-position endpos))
6490 (verilog-just-one-space verilog-assignment-operation-re) 6557 (beginning-of-line)
6491 (beginning-of-line) 6558 (verilog-just-one-space verilog-assignment-operation-re)
6492 (verilog-do-indent (verilog-calculate-indent)) 6559 (beginning-of-line)
6493 (end-of-line) 6560 (verilog-do-indent (verilog-calculate-indent))
6494 (verilog-forward-syntactic-ws) 6561 (end-of-line)
6495 ) 6562 (verilog-forward-syntactic-ws)
6496 6563 )
6497 ;; Now find biggest prefix 6564
6498 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos)) 6565 ;; Now find biggest prefix
6499 6566 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
6500 ;; Now indent each line. 6567
6501 (goto-char start) 6568 ;; Now indent each line.
6502 (while (progn (setq e (marker-position endpos)) 6569 (goto-char start)
6503 (setq r (- e (point))) 6570 (while (progn (setq e (marker-position endpos))
6504 (> r 0)) 6571 (setq r (- e (point)))
6505 (setq e (point)) 6572 (> r 0))
6506 (if (not quiet) (message "%d" r)) 6573 (setq e (point))
6507 (cond 6574 (if (not quiet) (message "%d" r))
6508 ((looking-at verilog-assignment-operation-re) 6575 (cond
6509 (goto-char (match-beginning 2)) 6576 ((looking-at verilog-assignment-operation-re)
6510 (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone 6577 (goto-char (match-beginning 2))
6511 (verilog-in-coverage-p))) 6578 (if (not (or (verilog-in-parenthesis-p) ;; leave attributes and comparisons alone
6512 (if (eq (char-after) ?=) 6579 (verilog-in-coverage-p)))
6513 (indent-to (1+ ind)) ; line up the = of the <= with surrounding = 6580 (if (eq (char-after) ?=)
6514 (indent-to ind) 6581 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
6515 )) 6582 (indent-to ind)
6516 ) 6583 ))
6517 ((verilog-continued-line-1 start) 6584 )
6518 (goto-char e) 6585 ((verilog-continued-line-1 start)
6519 (indent-line-to ind)) 6586 (goto-char e)
6520 (t ; Must be comment or white space 6587 (indent-line-to ind))
6521 (goto-char e) 6588 (t ; Must be comment or white space
6522 (verilog-forward-ws&directives) 6589 (goto-char e)
6523 (forward-line -1)) 6590 (verilog-forward-ws&directives)
6524 ) 6591 (forward-line -1))
6525 (forward-line 1)) 6592 )
6526 (unless quiet (message "")) 6593 (forward-line 1))
6527 )))))) 6594 (unless quiet (message ""))
6595 ))))))
6528 6596
6529(defun verilog-just-one-space (myre) 6597(defun verilog-just-one-space (myre)
6530 "Remove extra spaces around regular expression MYRE." 6598 "Remove extra spaces around regular expression MYRE."
@@ -7365,6 +7433,7 @@ See also `verilog-sk-header' for an alternative format."
7365;; 7433;;
7366 7434
7367;; Elements of a signal list 7435;; Elements of a signal list
7436;; Unfortunately we use 'assoc' on this, so can't be a vector
7368(defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport) 7437(defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7369 (list name bits comment mem enum signed type multidim modport)) 7438 (list name bits comment mem enum signed type multidim modport))
7370(defsubst verilog-sig-name (sig) 7439(defsubst verilog-sig-name (sig)
@@ -7381,6 +7450,8 @@ See also `verilog-sk-header' for an alternative format."
7381 (nth 5 sig)) 7450 (nth 5 sig))
7382(defsubst verilog-sig-type (sig) 7451(defsubst verilog-sig-type (sig)
7383 (nth 6 sig)) 7452 (nth 6 sig))
7453(defsubst verilog-sig-type-set (sig type)
7454 (setcar (nthcdr 6 sig) type))
7384(defsubst verilog-sig-multidim (sig) 7455(defsubst verilog-sig-multidim (sig)
7385 (nth 7 sig)) 7456 (nth 7 sig))
7386(defsubst verilog-sig-multidim-string (sig) 7457(defsubst verilog-sig-multidim-string (sig)
@@ -7396,17 +7467,17 @@ See also `verilog-sk-header' for an alternative format."
7396 (verilog-make-width-expression (verilog-sig-bits sig))) 7467 (verilog-make-width-expression (verilog-sig-bits sig)))
7397 7468
7398(defsubst verilog-alw-new (outputs-del outputs-imm temps inputs) 7469(defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7399 (list outputs-del outputs-imm temps inputs)) 7470 (vector outputs-del outputs-imm temps inputs))
7400(defsubst verilog-alw-get-outputs-delayed (sigs) 7471(defsubst verilog-alw-get-outputs-delayed (sigs)
7401 (nth 0 sigs)) 7472 (aref sigs 0))
7402(defsubst verilog-alw-get-outputs-immediate (sigs) 7473(defsubst verilog-alw-get-outputs-immediate (sigs)
7403 (nth 1 sigs)) 7474 (aref sigs 1))
7404(defsubst verilog-alw-get-temps (sigs) 7475(defsubst verilog-alw-get-temps (sigs)
7405 (nth 2 sigs)) 7476 (aref sigs 2))
7406(defsubst verilog-alw-get-inputs (sigs) 7477(defsubst verilog-alw-get-inputs (sigs)
7407 (nth 3 sigs)) 7478 (aref sigs 3))
7408(defsubst verilog-alw-get-uses-delayed (sigs) 7479(defsubst verilog-alw-get-uses-delayed (sigs)
7409 (nth 0 sigs)) 7480 (aref sigs 0))
7410 7481
7411(defsubst verilog-modi-new (name fob pt type) 7482(defsubst verilog-modi-new (name fob pt type)
7412 (vector name fob pt type)) 7483 (vector name fob pt type))
@@ -7459,6 +7530,11 @@ See also `verilog-sk-header' for an alternative format."
7459(defsubst verilog-subdecls-get-interfaced (subdecls) 7530(defsubst verilog-subdecls-get-interfaced (subdecls)
7460 (aref subdecls 4)) 7531 (aref subdecls 4))
7461 7532
7533(defun verilog-signals-from-signame (signame-list)
7534 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
7535 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
7536 signame-list))
7537
7462(defun verilog-signals-not-in (in-list not-list) 7538(defun verilog-signals-not-in (in-list not-list)
7463 "Return list of signals in IN-LIST that aren't also in NOT-LIST. 7539 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
7464Also remove any duplicates in IN-LIST. 7540Also remove any duplicates in IN-LIST.
@@ -7471,17 +7547,17 @@ Signals must be in standard (base vector) form."
7471 (puthash (car (car not-list)) t ht) 7547 (puthash (car (car not-list)) t ht)
7472 (setq not-list (cdr not-list))) 7548 (setq not-list (cdr not-list)))
7473 (while in-list 7549 (while in-list
7474 (when (not (gethash (car (car in-list)) ht)) 7550 (when (not (gethash (verilog-sig-name (car in-list)) ht))
7475 (setq out-list (cons (car in-list) out-list)) 7551 (setq out-list (cons (car in-list) out-list))
7476 (puthash (car (car in-list)) t ht)) 7552 (puthash (verilog-sig-name (car in-list)) t ht))
7477 (setq in-list (cdr in-list))) 7553 (setq in-list (cdr in-list)))
7478 (nreverse out-list))) 7554 (nreverse out-list)))
7479 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4) 7555 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
7480 (t 7556 (t
7481 (let (out-list) 7557 (let (out-list)
7482 (while in-list 7558 (while in-list
7483 (if (not (or (assoc (car (car in-list)) not-list) 7559 (if (not (or (assoc (verilog-sig-name (car in-list)) not-list)
7484 (assoc (car (car in-list)) out-list))) 7560 (assoc (verilog-sig-name (car in-list)) out-list)))
7485 (setq out-list (cons (car in-list) out-list))) 7561 (setq out-list (cons (car in-list) out-list)))
7486 (setq in-list (cdr in-list))) 7562 (setq in-list (cdr in-list)))
7487 (nreverse out-list))))) 7563 (nreverse out-list)))))
@@ -7499,13 +7575,22 @@ Signals must be in standard (base vector) form."
7499 7575
7500(defun verilog-signals-sort-compare (a b) 7576(defun verilog-signals-sort-compare (a b)
7501 "Compare signal A and B for sorting." 7577 "Compare signal A and B for sorting."
7502 (string< (car a) (car b))) 7578 (string< (verilog-sig-name a) (verilog-sig-name b)))
7503 7579
7504(defun verilog-signals-not-params (in-list) 7580(defun verilog-signals-not-params (in-list)
7505 "Return list of signals in IN-LIST that aren't parameters or numeric constants." 7581 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
7506 (let (out-list) 7582 (let (out-list)
7507 (while in-list 7583 (while in-list
7508 (unless (boundp (intern (concat "vh-" (car (car in-list))))) 7584 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
7585 (setq out-list (cons (car in-list) out-list)))
7586 (setq in-list (cdr in-list)))
7587 (nreverse out-list)))
7588
7589(defun verilog-signals-with (func in-list)
7590 "Return IN-LIST with only signals where FUNC passed each signal is true."
7591 (let (out-list)
7592 (while in-list
7593 (when (funcall func (car in-list))
7509 (setq out-list (cons (car in-list) out-list))) 7594 (setq out-list (cons (car in-list) out-list)))
7510 (setq in-list (cdr in-list))) 7595 (setq in-list (cdr in-list)))
7511 (nreverse out-list))) 7596 (nreverse out-list)))
@@ -7594,20 +7679,67 @@ Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
7594 ;; 7679 ;;
7595 out-list)) 7680 out-list))
7596 7681
7597(defun verilog-sig-tieoff (sig &optional no-width) 7682(defun verilog-sig-tieoff (sig)
7598 "Return tieoff expression for given SIG, with appropriate width. 7683 "Return tieoff expression for given SIG, with appropriate width.
7599Ignore width if optional NO-WIDTH is set." 7684Tieoff value uses `verilog-active-low-regexp' and
7600 (let* ((width (if no-width nil (verilog-sig-width sig)))) 7685`verilog-auto-reset-widths'."
7601 (concat 7686 (concat
7602 (if (and verilog-active-low-regexp 7687 (if (and verilog-active-low-regexp
7603 (string-match verilog-active-low-regexp (verilog-sig-name sig))) 7688 (string-match verilog-active-low-regexp (verilog-sig-name sig)))
7604 "~" "") 7689 "~" "")
7605 (cond ((not width) 7690 (cond ((not verilog-auto-reset-widths)
7606 "0") 7691 "0")
7607 ((string-match "^[0-9]+$" width) 7692 ((equal verilog-auto-reset-widths 'unbased)
7608 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))) 7693 "'0")
7609 (t 7694 ;; Else presume verilog-auto-reset-widths is true
7610 (concat "{" width "{1'b0}}")))))) 7695 (t
7696 (let* ((width (verilog-sig-width sig)))
7697 (if (string-match "^[0-9]+$" width)
7698 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))
7699 (concat "{" width "{1'b0}}")))))))
7700
7701;;
7702;; Dumping
7703;;
7704
7705(defun verilog-decls-princ (decls)
7706 "For debug, dump the `verilog-read-decls' structure DECLS."
7707 (verilog-signals-princ (verilog-decls-get-outputs decls)
7708 "Outputs:\n" " ")
7709 (verilog-signals-princ (verilog-decls-get-inouts decls)
7710 "Inout:\n" " ")
7711 (verilog-signals-princ (verilog-decls-get-inputs decls)
7712 "Inputs:\n" " ")
7713 (verilog-signals-princ (verilog-decls-get-vars decls)
7714 "Vars:\n" " ")
7715 (verilog-signals-princ (verilog-decls-get-assigns decls)
7716 "Assigns:\n" " ")
7717 (verilog-signals-princ (verilog-decls-get-consts decls)
7718 "Consts:\n" " ")
7719 (verilog-signals-princ (verilog-decls-get-gparams decls)
7720 "Gparams:\n" " ")
7721 (verilog-signals-princ (verilog-decls-get-interfaces decls)
7722 "Interfaces:\n" " ")
7723 (princ "\n"))
7724
7725(defun verilog-signals-princ (signals &optional header prefix)
7726 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
7727 (when signals
7728 (princ header)
7729 (while signals
7730 (let ((sig (car signals)))
7731 (setq signals (cdr signals))
7732 (princ prefix)
7733 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
7734 (princ " bits=") (princ (verilog-sig-bits sig))
7735 (princ " cmt=") (princ (verilog-sig-comment sig))
7736 (princ " mem=") (princ (verilog-sig-memory sig))
7737 (princ " enum=") (princ (verilog-sig-enum sig))
7738 (princ " sign=") (princ (verilog-sig-signed sig))
7739 (princ " type=") (princ (verilog-sig-type sig))
7740 (princ " dim=") (princ (verilog-sig-multidim sig))
7741 (princ " modp=") (princ (verilog-sig-modport sig))
7742 (princ "\n")))))
7611 7743
7612;; 7744;;
7613;; Port/Wire/Etc Reading 7745;; Port/Wire/Etc Reading
@@ -7701,7 +7833,7 @@ Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
7701 (let ((olist)) 7833 (let ((olist))
7702 (save-excursion 7834 (save-excursion
7703 ;; /*AUTOPUNT("parameter", "parameter")*/ 7835 ;; /*AUTOPUNT("parameter", "parameter")*/
7704 (search-backward "(") 7836 (backward-sexp 1)
7705 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?") 7837 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
7706 (setq olist (cons (match-string 1) olist)) 7838 (setq olist (cons (match-string 1) olist))
7707 (goto-char (match-end 0)))) 7839 (goto-char (match-end 0))))
@@ -7716,10 +7848,10 @@ Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
7716 7848
7717(defun verilog-read-decls () 7849(defun verilog-read-decls ()
7718 "Compute signal declaration information for the current module at point. 7850 "Compute signal declaration information for the current module at point.
7719Return a array of [outputs inouts inputs wire reg assign const]." 7851Return an array of [outputs inouts inputs wire reg assign const]."
7720 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max))) 7852 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
7721 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t) 7853 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
7722 in-modport ign-prop 7854 in-modport ptype ign-prop
7723 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const 7855 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
7724 sigs-gparam sigs-intf 7856 sigs-gparam sigs-intf
7725 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim 7857 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
@@ -7731,13 +7863,13 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7731 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd)))) 7863 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
7732 (cond 7864 (cond
7733 ((looking-at "//") 7865 ((looking-at "//")
7734 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 7866 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7735 (setq enum (match-string 1))) 7867 (setq enum (match-string 2)))
7736 (search-forward "\n")) 7868 (search-forward "\n"))
7737 ((looking-at "/\\*") 7869 ((looking-at "/\\*")
7738 (forward-char 2) 7870 (forward-char 2)
7739 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 7871 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
7740 (setq enum (match-string 1))) 7872 (setq enum (match-string 2)))
7741 (or (search-forward "*/") 7873 (or (search-forward "*/")
7742 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) 7874 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
7743 ((looking-at "(\\*") 7875 ((looking-at "(\\*")
@@ -7795,33 +7927,49 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7795 (when (string-match "^\\\\" (match-string 1)) 7927 (when (string-match "^\\\\" (match-string 1))
7796 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end 7928 (setq keywd (concat keywd " ")))) ;; Escaped ID needs space at end
7797 (cond ((equal keywd "input") 7929 (cond ((equal keywd "input")
7798 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren 7930 (setq vec nil enum nil rvalue nil newsig nil signed nil
7799 expect-signal 'sigs-in io t modport nil)) 7931 typedefed nil multidim nil ptype nil modport nil
7932 expect-signal 'sigs-in io t sig-paren paren))
7800 ((equal keywd "output") 7933 ((equal keywd "output")
7801 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren 7934 (setq vec nil enum nil rvalue nil newsig nil signed nil
7802 expect-signal 'sigs-out io t modport nil)) 7935 typedefed nil multidim nil ptype nil modport nil
7936 expect-signal 'sigs-out io t sig-paren paren))
7803 ((equal keywd "inout") 7937 ((equal keywd "inout")
7804 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren 7938 (setq vec nil enum nil rvalue nil newsig nil signed nil
7805 expect-signal 'sigs-inout io t modport nil)) 7939 typedefed nil multidim nil ptype nil modport nil
7940 expect-signal 'sigs-inout io t sig-paren paren))
7806 ((equal keywd "parameter") 7941 ((equal keywd "parameter")
7807 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7942 (setq vec nil enum nil rvalue nil signed nil
7808 expect-signal 'sigs-gparam io t modport nil)) 7943 typedefed nil multidim nil ptype nil modport nil
7809 ((member keywd '("wire" 7944 expect-signal 'sigs-gparam io t sig-paren paren))
7810 "tri" "tri0" "tri1" "triand" "trior" "wand" "wor" 7945 ((member keywd '("wire" "reg" ; Fast
7811 "reg" "trireg" 7946 ;; net_type
7947 "tri" "tri0" "tri1" "triand" "trior" "trireg"
7948 "uwire" "wand" "wor"
7949 ;; integer_atom_type
7812 "byte" "shortint" "int" "longint" "integer" "time" 7950 "byte" "shortint" "int" "longint" "integer" "time"
7951 "supply0" "supply1"
7952 ;; integer_vector_type - "reg" above
7813 "bit" "logic" 7953 "bit" "logic"
7954 ;; non_integer_type
7814 "shortreal" "real" "realtime" 7955 "shortreal" "real" "realtime"
7956 ;; data_type
7815 "string" "event" "chandle")) 7957 "string" "event" "chandle"))
7816 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7958 (cond (io
7817 expect-signal 'sigs-var modport nil))) 7959 (setq typedefed
7960 (if typedefed (concat typedefed " " keywd) keywd)))
7961 (t (setq vec nil enum nil rvalue nil signed nil
7962 typedefed nil multidim nil sig-paren paren
7963 expect-signal 'sigs-var modport nil))))
7818 ((equal keywd "assign") 7964 ((equal keywd "assign")
7819 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7965 (setq vec nil enum nil rvalue nil signed nil
7820 expect-signal 'sigs-assign modport nil)) 7966 typedefed nil multidim nil ptype nil modport nil
7821 ((member keywd '("supply0" "supply1" "supply" 7967 expect-signal 'sigs-assign sig-paren paren))
7822 "localparam" "genvar")) 7968 ((member keywd '("localparam" "genvar"))
7823 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 7969 (unless io
7824 expect-signal 'sigs-const modport nil))) 7970 (setq vec nil enum nil rvalue nil signed nil
7971 typedefed nil multidim nil ptype nil modport nil
7972 expect-signal 'sigs-const sig-paren paren)))
7825 ((member keywd '("signed" "unsigned")) 7973 ((member keywd '("signed" "unsigned"))
7826 (setq signed keywd)) 7974 (setq signed keywd))
7827 ((member keywd '("assert" "assume" "cover" "expect" "restrict")) 7975 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
@@ -7835,11 +7983,14 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7835 (setq functask (1- functask))) 7983 (setq functask (1- functask)))
7836 ((equal keywd "modport") 7984 ((equal keywd "modport")
7837 (setq in-modport t)) 7985 (setq in-modport t))
7986 ((equal keywd "type")
7987 (setq ptype t))
7838 ;; Ifdef? Ignore name of define 7988 ;; Ifdef? Ignore name of define
7839 ((member keywd '("`ifdef" "`ifndef" "`elsif")) 7989 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
7840 (setq rvalue t)) 7990 (setq rvalue t))
7841 ;; Type? 7991 ;; Type?
7842 ((verilog-typedef-name-p keywd) 7992 ((unless ptype
7993 (verilog-typedef-name-p keywd))
7843 (setq typedefed keywd)) 7994 (setq typedefed keywd))
7844 ;; Interface with optional modport in v2k arglist? 7995 ;; Interface with optional modport in v2k arglist?
7845 ;; Skip over parsing modport, and take the interface name as the type 7996 ;; Skip over parsing modport, and take the interface name as the type
@@ -7848,8 +7999,10 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7848 (not rvalue) 7999 (not rvalue)
7849 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*")) 8000 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
7850 (when (match-end 2) (goto-char (match-end 2))) 8001 (when (match-end 2) (goto-char (match-end 2)))
7851 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed keywd multidim nil sig-paren paren 8002 (setq vec nil enum nil rvalue nil signed nil
7852 expect-signal 'sigs-intf io t modport (match-string 2))) 8003 typedefed keywd multidim nil ptype nil modport (match-string 2)
8004 newsig nil sig-paren paren
8005 expect-signal 'sigs-intf io t ))
7853 ;; Ignore dotted LHS assignments: "assign foo.bar = z;" 8006 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
7854 ((looking-at "\\s-*\\.") 8007 ((looking-at "\\s-*\\.")
7855 (goto-char (match-end 0)) 8008 (goto-char (match-end 0))
@@ -7888,7 +8041,7 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7888(eval-when-compile 8041(eval-when-compile
7889 ;; Prevent compile warnings; these are let's, not globals 8042 ;; Prevent compile warnings; these are let's, not globals
7890 ;; Do not remove the eval-when-compile 8043 ;; Do not remove the eval-when-compile
7891 ;; - we want a error when we are debugging this code if they are refed. 8044 ;; - we want an error when we are debugging this code if they are refed.
7892 (defvar sigs-in) 8045 (defvar sigs-in)
7893 (defvar sigs-inout) 8046 (defvar sigs-inout)
7894 (defvar sigs-out) 8047 (defvar sigs-out)
@@ -7918,7 +8071,8 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7918 (verilog-sig-memory portdata) 8071 (verilog-sig-memory portdata)
7919 nil 8072 nil
7920 (verilog-sig-signed portdata) 8073 (verilog-sig-signed portdata)
7921 (verilog-sig-type portdata) 8074 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8075 (verilog-sig-type portdata))
7922 multidim nil) 8076 multidim nil)
7923 sigs-inout))) 8077 sigs-inout)))
7924 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls))) 8078 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
@@ -7931,7 +8085,13 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7931 (verilog-sig-memory portdata) 8085 (verilog-sig-memory portdata)
7932 nil 8086 nil
7933 (verilog-sig-signed portdata) 8087 (verilog-sig-signed portdata)
7934 (verilog-sig-type portdata) 8088 ;; Though ok in SV, in V2K code, propagating the
8089 ;; "reg" in "output reg" upwards isn't legal.
8090 ;; Also for backwards compatibility we don't propagate
8091 ;; "input wire" upwards.
8092 ;; See also `verilog-signals-edit-wire-reg'.
8093 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8094 (verilog-sig-type portdata))
7935 multidim nil) 8095 multidim nil)
7936 sigs-out))) 8096 sigs-out)))
7937 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls))) 8097 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
@@ -7944,7 +8104,8 @@ Return a array of [outputs inouts inputs wire reg assign const]."
7944 (verilog-sig-memory portdata) 8104 (verilog-sig-memory portdata)
7945 nil 8105 nil
7946 (verilog-sig-signed portdata) 8106 (verilog-sig-signed portdata)
7947 (verilog-sig-type portdata) 8107 (unless (member (verilog-sig-type portdata) '("wire" "reg"))
8108 (verilog-sig-type portdata))
7948 multidim nil) 8109 multidim nil)
7949 sigs-in))) 8110 sigs-in)))
7950 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls))) 8111 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
@@ -8110,9 +8271,9 @@ Inserts the list of signals found."
8110 8271
8111(defun verilog-read-sub-decls () 8272(defun verilog-read-sub-decls ()
8112 "Internally parse signals going to modules under this module. 8273 "Internally parse signals going to modules under this module.
8113Return a array of [ outputs inouts inputs ] signals for modules that are 8274Return an array of [ outputs inouts inputs ] signals for modules that are
8114instantiated in this module. For example if declare A A (.B(SIG)) and SIG 8275instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8115is a output, then SIG will be included in the list. 8276is an output, then SIG will be included in the list.
8116 8277
8117This only works on instantiations created with /*AUTOINST*/ converted by 8278This only works on instantiations created with /*AUTOINST*/ converted by
8118\\[verilog-auto-inst]. Otherwise, it would have to read in the whole 8279\\[verilog-auto-inst]. Otherwise, it would have to read in the whole
@@ -8245,7 +8406,7 @@ For example if declare A A (.B(SIG)) then B will be included in the list."
8245 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t)))) 8406 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
8246 8407
8247(defun verilog-read-auto-lisp (start end) 8408(defun verilog-read-auto-lisp (start end)
8248 "Look for and evaluate a AUTO_LISP between START and END. 8409 "Look for and evaluate an AUTO_LISP between START and END.
8249Must call `verilog-read-auto-lisp-present' before this function." 8410Must call `verilog-read-auto-lisp-present' before this function."
8250 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists 8411 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
8251 (when verilog-cache-has-lisp 8412 (when verilog-cache-has-lisp
@@ -8255,13 +8416,14 @@ Must call `verilog-read-auto-lisp-present' before this function."
8255 (backward-char) 8416 (backward-char)
8256 (let* ((beg-pt (prog1 (point) 8417 (let* ((beg-pt (prog1 (point)
8257 (verilog-forward-sexp-cmt 1))) ;; Closing paren 8418 (verilog-forward-sexp-cmt 1))) ;; Closing paren
8258 (end-pt (point))) 8419 (end-pt (point))
8420 (verilog-in-hooks t))
8259 (eval-region beg-pt end-pt nil)))))) 8421 (eval-region beg-pt end-pt nil))))))
8260 8422
8261(eval-when-compile 8423(eval-when-compile
8262 ;; Prevent compile warnings; these are let's, not globals 8424 ;; Prevent compile warnings; these are let's, not globals
8263 ;; Do not remove the eval-when-compile 8425 ;; Do not remove the eval-when-compile
8264 ;; - we want a error when we are debugging this code if they are refed. 8426 ;; - we want an error when we are debugging this code if they are refed.
8265 (defvar sigs-in) 8427 (defvar sigs-in)
8266 (defvar sigs-out-d) 8428 (defvar sigs-out-d)
8267 (defvar sigs-out-i) 8429 (defvar sigs-out-i)
@@ -8455,17 +8617,89 @@ IGNORE-NEXT is true to ignore next token, fake from inside case statement."
8455 instants-list)) 8617 instants-list))
8456 8618
8457 8619
8458(defun verilog-read-auto-template (module) 8620(defun verilog-read-auto-template-middle ()
8459 "Look for a auto_template for the instantiation of the given MODULE. 8621 "With point in middle of an AUTO_TEMPLATE, parse it.
8460If found returns the signal name connections. Return REGEXP and 8622Returns REGEXP and list of ( (signal_name connection_name)... )."
8461list of ( (signal_name connection_name)... )."
8462 (save-excursion 8623 (save-excursion
8463 ;; Find beginning 8624 ;; Find beginning
8464 (let ((tpl-regexp "\\([0-9]+\\)") 8625 (let ((tpl-regexp "\\([0-9]+\\)")
8465 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline 8626 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
8466 (templateno 0) 8627 (templateno 0)
8467 (pt (point))
8468 tpl-sig-list tpl-wild-list tpl-end-pt rep) 8628 tpl-sig-list tpl-wild-list tpl-end-pt rep)
8629 ;; Parse "REGEXP"
8630 ;; We reserve @"..." for future lisp expressions that evaluate
8631 ;; once-per-AUTOINST
8632 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
8633 (setq tpl-regexp (match-string 1))
8634 (goto-char (match-end 0)))
8635 (search-forward "(")
8636 ;; Parse lines in the template
8637 (when (or verilog-auto-inst-template-numbers
8638 verilog-auto-template-warn-unused)
8639 (save-excursion
8640 (let ((pre-pt (point)))
8641 (goto-char (point-min))
8642 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
8643 (setq templateno (1+ templateno)))
8644 (while (< (point) pre-pt)
8645 (forward-line 1)
8646 (setq lineno (1+ lineno))))))
8647 (setq tpl-end-pt (save-excursion
8648 (backward-char 1)
8649 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8650 (backward-char 1)
8651 (point)))
8652 ;;
8653 (while (< (point) tpl-end-pt)
8654 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8655 (setq tpl-sig-list
8656 (cons (list
8657 (match-string-no-properties 1)
8658 (match-string-no-properties 2)
8659 templateno lineno)
8660 tpl-sig-list))
8661 (goto-char (match-end 0)))
8662 ;; Regexp form??
8663 ((looking-at
8664 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
8665 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8666 (setq rep (match-string-no-properties 3))
8667 (goto-char (match-end 0))
8668 (setq tpl-wild-list
8669 (cons (list
8670 (concat "^"
8671 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8672 (match-string 1))
8673 "$")
8674 rep
8675 templateno lineno)
8676 tpl-wild-list)))
8677 ((looking-at "[ \t\f]+")
8678 (goto-char (match-end 0)))
8679 ((looking-at "\n")
8680 (setq lineno (1+ lineno))
8681 (goto-char (match-end 0)))
8682 ((looking-at "//")
8683 (search-forward "\n")
8684 (setq lineno (1+ lineno)))
8685 ((looking-at "/\\*")
8686 (forward-char 2)
8687 (or (search-forward "*/")
8688 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8689 (t
8690 (error "%s: AUTO_TEMPLATE parsing error: %s"
8691 (verilog-point-text)
8692 (progn (looking-at ".*$") (match-string 0))))))
8693 ;; Return
8694 (vector tpl-regexp
8695 (list tpl-sig-list tpl-wild-list)))))
8696
8697(defun verilog-read-auto-template (module)
8698 "Look for an auto_template for the instantiation of the given MODULE.
8699If found returns `verilog-read-auto-template-inside' structure."
8700 (save-excursion
8701 ;; Find beginning
8702 (let ((pt (point)))
8469 ;; Note this search is expensive, as we hunt from mod-begin to point 8703 ;; Note this search is expensive, as we hunt from mod-begin to point
8470 ;; for every instantiation. Likewise in verilog-read-auto-lisp. 8704 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
8471 ;; So, we look first for an exact string rather than a slow regexp. 8705 ;; So, we look first for an exact string rather than a slow regexp.
@@ -8473,6 +8707,7 @@ list of ( (signal_name connection_name)... )."
8473 ;; need to record the relative position of each AUTOINST, as multiple 8707 ;; need to record the relative position of each AUTOINST, as multiple
8474 ;; templates exist for each module, and we're inserting lines. 8708 ;; templates exist for each module, and we're inserting lines.
8475 (cond ((or 8709 (cond ((or
8710 ;; See also regexp in `verilog-auto-template-lint'
8476 (verilog-re-search-backward-substr 8711 (verilog-re-search-backward-substr
8477 "AUTO_TEMPLATE" 8712 "AUTO_TEMPLATE"
8478 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t) 8713 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
@@ -8484,76 +8719,24 @@ list of ( (signal_name connection_name)... )."
8484 "AUTO_TEMPLATE" 8719 "AUTO_TEMPLATE"
8485 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t))) 8720 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
8486 (goto-char (match-end 0)) 8721 (goto-char (match-end 0))
8487 ;; Parse "REGEXP" 8722 (verilog-read-auto-template-middle))
8488 ;; We reserve @"..." for future lisp expressions that evaluate
8489 ;; once-per-AUTOINST
8490 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
8491 (setq tpl-regexp (match-string 1))
8492 (goto-char (match-end 0)))
8493 (search-forward "(")
8494 ;; Parse lines in the template
8495 (when verilog-auto-inst-template-numbers
8496 (save-excursion
8497 (let ((pre-pt (point)))
8498 (goto-char (point-min))
8499 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
8500 (setq templateno (1+ templateno)))
8501 (while (< (point) pre-pt)
8502 (forward-line 1)
8503 (setq lineno (1+ lineno))))))
8504 (setq tpl-end-pt (save-excursion
8505 (backward-char 1)
8506 (verilog-forward-sexp-cmt 1) ;; Moves to paren that closes argdecl's
8507 (backward-char 1)
8508 (point)))
8509 ;;
8510 (while (< (point) tpl-end-pt)
8511 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8512 (setq tpl-sig-list
8513 (cons (list
8514 (match-string-no-properties 1)
8515 (match-string-no-properties 2)
8516 templateno lineno)
8517 tpl-sig-list))
8518 (goto-char (match-end 0)))
8519 ;; Regexp form??
8520 ((looking-at
8521 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
8522 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
8523 (setq rep (match-string-no-properties 3))
8524 (goto-char (match-end 0))
8525 (setq tpl-wild-list
8526 (cons (list
8527 (concat "^"
8528 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
8529 (match-string 1))
8530 "$")
8531 rep
8532 templateno lineno)
8533 tpl-wild-list)))
8534 ((looking-at "[ \t\f]+")
8535 (goto-char (match-end 0)))
8536 ((looking-at "\n")
8537 (setq lineno (1+ lineno))
8538 (goto-char (match-end 0)))
8539 ((looking-at "//")
8540 (search-forward "\n")
8541 (setq lineno (1+ lineno)))
8542 ((looking-at "/\\*")
8543 (forward-char 2)
8544 (or (search-forward "*/")
8545 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8546 (t
8547 (error "%s: AUTO_TEMPLATE parsing error: %s"
8548 (verilog-point-text)
8549 (progn (looking-at ".*$") (match-string 0))))))
8550 ;; Return
8551 (vector tpl-regexp
8552 (list tpl-sig-list tpl-wild-list)))
8553 ;; If no template found 8723 ;; If no template found
8554 (t (vector tpl-regexp nil)))))) 8724 (t (vector "" nil))))))
8555;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry")) 8725;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
8556 8726
8727(defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
8728(make-variable-buffer-local 'verilog-auto-template-hits)
8729
8730(defun verilog-read-auto-template-hit (tpl-ass)
8731 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
8732 (when (eval-when-compile (fboundp 'make-hash-table)) ;; else feature not allowed
8733 (when verilog-auto-template-warn-unused
8734 (unless verilog-auto-template-hits
8735 (setq verilog-auto-template-hits
8736 (make-hash-table :test 'equal :rehash-size 4.0)))
8737 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
8738 verilog-auto-template-hits))))
8739
8557(defun verilog-set-define (defname defvalue &optional buffer enumname) 8740(defun verilog-set-define (defname defvalue &optional buffer enumname)
8558 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER. 8741 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
8559Optionally associate it with the specified enumeration ENUMNAME." 8742Optionally associate it with the specified enumeration ENUMNAME."
@@ -8642,15 +8825,15 @@ warning message, you need to add to your .emacs file:
8642 (let (enumname) 8825 (let (enumname)
8643 ;; The primary way of getting defines is verilog-read-decls 8826 ;; The primary way of getting defines is verilog-read-decls
8644 ;; However, that isn't called yet for included files, so we'll add another scheme 8827 ;; However, that isn't called yet for included files, so we'll add another scheme
8645 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 8828 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8646 (setq enumname (match-string-no-properties 1))) 8829 (setq enumname (match-string-no-properties 2)))
8647 (forward-comment 999) 8830 (forward-comment 99999)
8648 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)" 8831 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
8649 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*")) 8832 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
8650 (verilog-set-define (match-string-no-properties 1) 8833 (verilog-set-define (match-string-no-properties 1)
8651 (match-string-no-properties 2) origbuf enumname) 8834 (match-string-no-properties 2) origbuf enumname)
8652 (goto-char (match-end 0)) 8835 (goto-char (match-end 0))
8653 (forward-comment 999))))))) 8836 (forward-comment 99999)))))))
8654 8837
8655(defun verilog-read-includes () 8838(defun verilog-read-includes ()
8656 "Read `includes for the current file. 8839 "Read `includes for the current file.
@@ -8675,7 +8858,7 @@ this process, Verilint, and readability. To prevent defining the same
8675variable over and over when many modules are compiled together, put a test 8858variable over and over when many modules are compiled together, put a test
8676around the inside each include file: 8859around the inside each include file:
8677 8860
8678foo.v (a include): 8861foo.v (an include file):
8679 `ifdef _FOO_V // include if not already included 8862 `ifdef _FOO_V // include if not already included
8680 `else 8863 `else
8681 `define _FOO_V 8864 `define _FOO_V
@@ -9038,7 +9221,7 @@ Or, just the existing dirnames themselves if there are no wildcards."
9038 9221
9039(defun verilog-library-filenames (filename &optional current check-ext) 9222(defun verilog-library-filenames (filename &optional current check-ext)
9040 "Return a search path to find the given FILENAME or module name. 9223 "Return a search path to find the given FILENAME or module name.
9041Uses the optional CURRENT filename or buffer-file-name, plus 9224Uses the optional CURRENT filename or variable `buffer-file-name', plus
9042`verilog-library-directories' and `verilog-library-extensions' 9225`verilog-library-directories' and `verilog-library-extensions'
9043variables to build the path. With optional CHECK-EXT also check 9226variables to build the path. With optional CHECK-EXT also check
9044`verilog-library-extensions'." 9227`verilog-library-extensions'."
@@ -9091,7 +9274,7 @@ variables to build the path."
9091;; A modi is: [module-name-string file-name begin-point] 9274;; A modi is: [module-name-string file-name begin-point]
9092 9275
9093(defvar verilog-cache-enabled t 9276(defvar verilog-cache-enabled t
9094 "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!") 9277 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
9095 9278
9096(defvar verilog-modi-cache-list nil 9279(defvar verilog-modi-cache-list nil
9097 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)... 9280 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
@@ -9106,7 +9289,7 @@ Use `verilog-preserve-modi-cache' to set it.")
9106 "Modification tick after which the cache is still considered valid. 9289 "Modification tick after which the cache is still considered valid.
9107Use `verilog-preserve-modi-cache' to set it.") 9290Use `verilog-preserve-modi-cache' to set it.")
9108(defvar verilog-modi-cache-current-enable nil 9291(defvar verilog-modi-cache-current-enable nil
9109 "If true, allow caching `verilog-modi-current', set by let().") 9292 "Non-nil means allow caching `verilog-modi-current', set by let().")
9110(defvar verilog-modi-cache-current nil 9293(defvar verilog-modi-cache-current nil
9111 "Currently active `verilog-modi-current', if any, set by let().") 9294 "Currently active `verilog-modi-current', if any, set by let().")
9112(defvar verilog-modi-cache-current-max nil 9295(defvar verilog-modi-cache-current-max nil
@@ -9245,13 +9428,9 @@ Cache the output of function so next call may have faster access."
9245 (t 9428 (t
9246 ;; Read from file 9429 ;; Read from file
9247 ;; Clear then restore any highlighting to make emacs19 happy 9430 ;; Clear then restore any highlighting to make emacs19 happy
9248 (let ((fontlocked (when (and (boundp 'font-lock-mode) 9431 (let (func-returns)
9249 font-lock-mode) 9432 (verilog-save-font-mods
9250 (font-lock-mode 0) 9433 (setq func-returns (funcall function)))
9251 t))
9252 func-returns)
9253 (setq func-returns (funcall function))
9254 (when fontlocked (font-lock-mode t))
9255 ;; Cache for next time 9434 ;; Cache for next time
9256 (setq verilog-modi-cache-list 9435 (setq verilog-modi-cache-list
9257 (cons (list (list modi function) 9436 (cons (list (list modi function)
@@ -9341,9 +9520,16 @@ if non-nil."
9341 (setq in-list (cdr in-list))) 9520 (setq in-list (cdr in-list)))
9342 (nreverse out-list)))) 9521 (nreverse out-list))))
9343 9522
9523(defun verilog-signals-edit-wire-reg (in-list)
9524 "Return all signals in IN-LIST with wire/reg data types made blank."
9525 (mapcar (lambda (sig)
9526 (when (member (verilog-sig-type sig) '("wire" "reg"))
9527 (verilog-sig-type-set sig nil))
9528 sig) in-list))
9529
9344;; Combined 9530;; Combined
9345(defun verilog-decls-get-signals (decls) 9531(defun verilog-decls-get-signals (decls)
9346 "Return all declared signals, excluding 'assign' statements." 9532 "Return all declared signals in DECLS, excluding 'assign' statements."
9347 (append 9533 (append
9348 (verilog-decls-get-outputs decls) 9534 (verilog-decls-get-outputs decls)
9349 (verilog-decls-get-inouts decls) 9535 (verilog-decls-get-inouts decls)
@@ -9367,10 +9553,6 @@ if non-nil."
9367(defsubst verilog-modi-cache-add-vars (modi sig-list) 9553(defsubst verilog-modi-cache-add-vars (modi sig-list)
9368 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list)) 9554 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
9369 9555
9370(defun verilog-signals-from-signame (signame-list)
9371 "Return signals in standard form from SIGNAME-LIST, a simple list of signal names."
9372 (mapcar (function (lambda (name) (list name nil nil)))
9373 signame-list))
9374 9556
9375;; 9557;;
9376;; Auto creation utilities 9558;; Auto creation utilities
@@ -9473,7 +9655,7 @@ Presumes that any newlines end a list element."
9473;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n")) 9655;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
9474 9656
9475(defun verilog-repair-open-comma () 9657(defun verilog-repair-open-comma ()
9476 "Insert comma if previous argument is other than a open parenthesis or endif." 9658 "Insert comma if previous argument is other than an open parenthesis or endif."
9477 ;; We can't just search backward for ) as it might be inside another expression. 9659 ;; We can't just search backward for ) as it might be inside another expression.
9478 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with 9660 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
9479 (save-excursion 9661 (save-excursion
@@ -9489,7 +9671,7 @@ Presumes that any newlines end a list element."
9489 9671
9490(defun verilog-repair-close-comma () 9672(defun verilog-repair-close-comma ()
9491 "If point is at a comma followed by a close parenthesis, fix it. 9673 "If point is at a comma followed by a close parenthesis, fix it.
9492This repairs those mis-inserted by a AUTOARG." 9674This repairs those mis-inserted by an AUTOARG."
9493 ;; It would be much nicer if Verilog allowed extra commas like Perl does! 9675 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
9494 (save-excursion 9676 (save-excursion
9495 (verilog-forward-close-paren) 9677 (verilog-forward-close-paren)
@@ -9974,15 +10156,16 @@ Ignores WHITESPACE if t, and writes output to stdout if SHOW."
9974Differences are between buffers B1 and B2, starting at point 10156Differences are between buffers B1 and B2, starting at point
9975DIFFPT. This function is called via `verilog-diff-function'." 10157DIFFPT. This function is called via `verilog-diff-function'."
9976 (let ((name1 (with-current-buffer b1 (buffer-file-name)))) 10158 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
9977 (message "%%Warning: %s:%d: Difference in AUTO expansion found" 10159 (verilog-warn "%s:%d: Difference in AUTO expansion found"
9978 name1 (with-current-buffer b1 (1+ (count-lines (point-min) (point))))) 10160 name1 (with-current-buffer b1
10161 (1+ (count-lines (point-min) (point)))))
9979 (cond (noninteractive 10162 (cond (noninteractive
9980 (verilog-diff-file-with-buffer name1 b2 t t)) 10163 (verilog-diff-file-with-buffer name1 b2 t t))
9981 (t 10164 (t
9982 (ediff-buffers b1 b2))))) 10165 (ediff-buffers b1 b2)))))
9983 10166
9984(defun verilog-diff-auto () 10167(defun verilog-diff-auto ()
9985 "Expand AUTOs in a temporary buffer and indicate any changes. 10168 "Expand AUTOs in a temporary buffer and indicate any change.
9986Whitespace differences are ignored to determine identicalness, but 10169Whitespace differences are ignored to determine identicalness, but
9987once a difference is detected, whitespace differences may be shown. 10170once a difference is detected, whitespace differences may be shown.
9988 10171
@@ -10076,7 +10259,7 @@ If FORCE, always reread it."
10076;; 10259;;
10077 10260
10078(defun verilog-auto-arg-ports (sigs message indent-pt) 10261(defun verilog-auto-arg-ports (sigs message indent-pt)
10079 "Print a list of ports for a AUTOINST. 10262 "Print a list of ports for an AUTOINST.
10080Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT." 10263Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
10081 (when sigs 10264 (when sigs
10082 (when verilog-auto-arg-sort 10265 (when verilog-auto-arg-sort
@@ -10178,7 +10361,7 @@ Avoid declaring ports manually, as it makes code harder to maintain."
10178(defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning 10361(defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
10179 10362
10180(defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values) 10363(defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
10181 "Print out a instantiation connection for this PORT-ST. 10364 "Print out an instantiation connection for this PORT-ST.
10182Insert to INDENT-PT, use template TPL-LIST. 10365Insert to INDENT-PT, use template TPL-LIST.
10183@ are instantiation numbers, replaced with TPL-NUM. 10366@ are instantiation numbers, replaced with TPL-NUM.
10184@\"(expression @)\" are evaluated, with @ as a variable. 10367@\"(expression @)\" are evaluated, with @ as a variable.
@@ -10266,6 +10449,7 @@ If PAR-VALUES replace final strings with these parameter values."
10266 (insert "(" tpl-net ")")) 10449 (insert "(" tpl-net ")"))
10267 (insert ",") 10450 (insert ",")
10268 (cond (tpl-ass 10451 (cond (tpl-ass
10452 (verilog-read-auto-template-hit tpl-ass)
10269 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) 10453 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
10270 verilog-auto-inst-column)) 10454 verilog-auto-inst-column))
10271 ;; verilog-insert requires the complete comment in one call - including the newline 10455 ;; verilog-insert requires the complete comment in one call - including the newline
@@ -10302,7 +10486,7 @@ If PAR-VALUES replace final strings with these parameter values."
10302(defun verilog-auto-inst-first () 10486(defun verilog-auto-inst-first ()
10303 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]." 10487 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
10304 ;; Do we need a trailing comma? 10488 ;; Do we need a trailing comma?
10305 ;; There maybe a ifdef or something similar before us. What a mess. Thus 10489 ;; There maybe an ifdef or something similar before us. What a mess. Thus
10306 ;; to avoid trouble we only insert on preceding ) or *. 10490 ;; to avoid trouble we only insert on preceding ) or *.
10307 ;; Insert first port on new line 10491 ;; Insert first port on new line
10308 (insert "\n") ;; Must insert before search, so point will move forward if insert comma 10492 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
@@ -10375,7 +10559,7 @@ For example, first take the submodule InstModule.v:
10375 wire [31:0] o = {32{i}}; 10559 wire [31:0] o = {32{i}};
10376 endmodule 10560 endmodule
10377 10561
10378This is then used in a upper level module: 10562This is then used in an upper level module:
10379 10563
10380 module ExampInst (o,i); 10564 module ExampInst (o,i);
10381 output o; 10565 output o;
@@ -10438,6 +10622,8 @@ Templates:
10438 expanded `verilog-mode' simply searches up for the closest template. 10622 expanded `verilog-mode' simply searches up for the closest template.
10439 Thus you can have multiple templates for the same module, just alternate 10623 Thus you can have multiple templates for the same module, just alternate
10440 between the template for an instantiation and the instantiation itself. 10624 between the template for an instantiation and the instantiation itself.
10625 (For backward compatibility if no template is found above, it
10626 will also look below, but do not use this behavior in new designs.)
10441 10627
10442 The module name must be the same as the name of the module in the 10628 The module name must be the same as the name of the module in the
10443 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact 10629 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
@@ -10456,6 +10642,9 @@ Templates:
10456 debugging is completed though, it will result in lots of extra differences 10642 debugging is completed though, it will result in lots of extra differences
10457 and merge conflicts. 10643 and merge conflicts.
10458 10644
10645 Setting `verilog-auto-template-warn-unused' will report errors
10646 if any template lines are unused.
10647
10459 For example: 10648 For example:
10460 10649
10461 /* InstModule AUTO_TEMPLATE ( 10650 /* InstModule AUTO_TEMPLATE (
@@ -10656,7 +10845,7 @@ For more information see the \\[verilog-faq] and forums at URL
10656 (when (and (not (member submod verilog-gate-keywords)) 10845 (when (and (not (member submod verilog-gate-keywords))
10657 (setq submodi (verilog-modi-lookup submod t))) 10846 (setq submodi (verilog-modi-lookup submod t)))
10658 (setq submoddecls (verilog-modi-get-decls submodi)) 10847 (setq submoddecls (verilog-modi-get-decls submodi))
10659 ;; If there's a number in the instantiation, it may be a argument to the 10848 ;; If there's a number in the instantiation, it may be an argument to the
10660 ;; automatic variable instantiation program. 10849 ;; automatic variable instantiation program.
10661 (let* ((tpl-info (verilog-read-auto-template submod)) 10850 (let* ((tpl-info (verilog-read-auto-template submod))
10662 (tpl-regexp (aref tpl-info 0))) 10851 (tpl-regexp (aref tpl-info 0)))
@@ -10670,7 +10859,8 @@ For more information see the \\[verilog-faq] and forums at URL
10670 (verilog-decls-get-vars submoddecls) 10859 (verilog-decls-get-vars submoddecls)
10671 skip-pins))) 10860 skip-pins)))
10672 (vl-dir "interfaced")) 10861 (vl-dir "interfaced"))
10673 (when sig-list 10862 (when (and sig-list
10863 verilog-auto-inst-interfaced-ports)
10674 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 10864 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
10675 ;; Note these are searched for in verilog-read-sub-decls. 10865 ;; Note these are searched for in verilog-read-sub-decls.
10676 (verilog-insert-indent "// Interfaced\n") 10866 (verilog-insert-indent "// Interfaced\n")
@@ -10740,7 +10930,7 @@ For example, first take the submodule InstModule.v:
10740 parameter PAR; 10930 parameter PAR;
10741 endmodule 10931 endmodule
10742 10932
10743This is then used in a upper level module: 10933This is then used in an upper level module:
10744 10934
10745 module ExampInst (o,i); 10935 module ExampInst (o,i);
10746 parameter PAR; 10936 parameter PAR;
@@ -10798,7 +10988,7 @@ Templates:
10798 ;; Note this may raise an error 10988 ;; Note this may raise an error
10799 (when (setq submodi (verilog-modi-lookup submod t)) 10989 (when (setq submodi (verilog-modi-lookup submod t))
10800 (setq submoddecls (verilog-modi-get-decls submodi)) 10990 (setq submoddecls (verilog-modi-get-decls submodi))
10801 ;; If there's a number in the instantiation, it may be a argument to the 10991 ;; If there's a number in the instantiation, it may be an argument to the
10802 ;; automatic variable instantiation program. 10992 ;; automatic variable instantiation program.
10803 (let* ((tpl-info (verilog-read-auto-template submod)) 10993 (let* ((tpl-info (verilog-read-auto-template submod))
10804 (tpl-regexp (aref tpl-info 0))) 10994 (tpl-regexp (aref tpl-info 0)))
@@ -10867,7 +11057,10 @@ Typing \\[verilog-auto] will make this into:
10867 (modsubdecls (verilog-modi-get-sub-decls modi)) 11057 (modsubdecls (verilog-modi-get-sub-decls modi))
10868 (sig-list (verilog-signals-not-in 11058 (sig-list (verilog-signals-not-in
10869 (verilog-decls-get-outputs moddecls) 11059 (verilog-decls-get-outputs moddecls)
10870 (append (verilog-decls-get-vars moddecls) 11060 (append (verilog-signals-with ;; ignore typed signals
11061 'verilog-sig-type
11062 (verilog-decls-get-outputs moddecls))
11063 (verilog-decls-get-vars moddecls)
10871 (verilog-decls-get-assigns moddecls) 11064 (verilog-decls-get-assigns moddecls)
10872 (verilog-decls-get-consts moddecls) 11065 (verilog-decls-get-consts moddecls)
10873 (verilog-decls-get-gparams moddecls) 11066 (verilog-decls-get-gparams moddecls)
@@ -10935,6 +11128,12 @@ Typing \\[verilog-auto] will make this into:
10935 (verilog-insert-definition modi sig-list "reg" indent-pt nil) 11128 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
10936 (verilog-insert-indent "// End of automatics\n"))))) 11129 (verilog-insert-indent "// End of automatics\n")))))
10937 11130
11131(defun verilog-auto-logic-setup ()
11132 "Prepare variables due to AUTOLOGIC."
11133 (unless verilog-auto-wire-type
11134 (set (make-local-variable 'verilog-auto-wire-type)
11135 "logic")))
11136
10938(defun verilog-auto-logic () 11137(defun verilog-auto-logic ()
10939 "Expand AUTOLOGIC statements, as part of \\[verilog-auto]. 11138 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
10940Make wire statements using the SystemVerilog logic keyword. 11139Make wire statements using the SystemVerilog logic keyword.
@@ -10951,15 +11150,13 @@ with the below at the bottom of the file
10951In the future AUTOLOGIC may declare additional identifiers, 11150In the future AUTOLOGIC may declare additional identifiers,
10952while AUTOWIRE will not." 11151while AUTOWIRE will not."
10953 (save-excursion 11152 (save-excursion
10954 (unless verilog-auto-wire-type 11153 (verilog-auto-logic-setup)
10955 (set (make-local-variable 'verilog-auto-wire-type)
10956 "logic"))
10957 (verilog-auto-wire))) 11154 (verilog-auto-wire)))
10958 11155
10959(defun verilog-auto-wire () 11156(defun verilog-auto-wire ()
10960 "Expand AUTOWIRE statements, as part of \\[verilog-auto]. 11157 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
10961Make wire statements for instantiations outputs that aren't 11158Make wire statements for instantiations outputs that aren't
10962already declared. `verilog-auto-wire-type' may be used to change 11159already declared. `verilog-auto-wire-type' may be used to change
10963the datatype of the declarations. 11160the datatype of the declarations.
10964 11161
10965Limitations: 11162Limitations:
@@ -11027,7 +11224,7 @@ Typing \\[verilog-auto] will make this into:
11027(defun verilog-auto-output (&optional with-params) 11224(defun verilog-auto-output (&optional with-params)
11028 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto]. 11225 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
11029Make output statements for any output signal from an /*AUTOINST*/ that 11226Make output statements for any output signal from an /*AUTOINST*/ that
11030isn't a input to another AUTOINST. This is useful for modules which 11227isn't an input to another AUTOINST. This is useful for modules which
11031only instantiate other modules. 11228only instantiate other modules.
11032 11229
11033Limitations: 11230Limitations:
@@ -11037,7 +11234,7 @@ Limitations:
11037 Verilog 2001 style, else uses Verilog 1995 style. 11234 Verilog 2001 style, else uses Verilog 1995 style.
11038 11235
11039 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's 11236 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11040 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). 11237 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11041 11238
11042 Typedefs must match `verilog-typedef-regexp', which is disabled by default. 11239 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11043 11240
@@ -11104,7 +11301,7 @@ same expansion will result from only extracting outputs starting with ov:
11104(defun verilog-auto-output-every () 11301(defun verilog-auto-output-every ()
11105 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto]. 11302 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
11106Make output statements for any signals that aren't primary inputs or 11303Make output statements for any signals that aren't primary inputs or
11107outputs already. This makes every signal in the design a output. This is 11304outputs already. This makes every signal in the design an output. This is
11108useful to get Synopsys to preserve every signal in the design, since it 11305useful to get Synopsys to preserve every signal in the design, since it
11109won't optimize away the outputs. 11306won't optimize away the outputs.
11110 11307
@@ -11164,7 +11361,7 @@ Limitations:
11164 Verilog 2001 style, else uses Verilog 1995 style. 11361 Verilog 2001 style, else uses Verilog 1995 style.
11165 11362
11166 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's 11363 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11167 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). 11364 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11168 11365
11169 Typedefs must match `verilog-typedef-regexp', which is disabled by default. 11366 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11170 11367
@@ -11243,7 +11440,7 @@ Limitations:
11243 Verilog 2001 style, else uses Verilog 1995 style. 11440 Verilog 2001 style, else uses Verilog 1995 style.
11244 11441
11245 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's 11442 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
11246 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). 11443 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
11247 11444
11248 Typedefs must match `verilog-typedef-regexp', which is disabled by default. 11445 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11249 11446
@@ -11326,9 +11523,14 @@ Limitations:
11326 Module names must be resolvable to filenames. See `verilog-auto-inst'. 11523 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11327 11524
11328 Signals are not inserted in the same order as in the original module, 11525 Signals are not inserted in the same order as in the original module,
11329 though they will appear to be in the same order to a AUTOINST 11526 though they will appear to be in the same order to an AUTOINST
11330 instantiating either module. 11527 instantiating either module.
11331 11528
11529 Signals declared as \"output reg\" or \"output wire\" etc will
11530 lose the wire/reg declaration so that shell modules may
11531 generate those outputs differently. However, \"output logic\"
11532 is propagated.
11533
11332An example: 11534An example:
11333 11535
11334 module ExampShell (/*AUTOARG*/); 11536 module ExampShell (/*AUTOARG*/);
@@ -11408,22 +11610,25 @@ against the previous example's module:
11408 (verilog-decls-get-interfaces submoddecls) 11610 (verilog-decls-get-interfaces submoddecls)
11409 (append (verilog-decls-get-interfaces moddecls))))) 11611 (append (verilog-decls-get-interfaces moddecls)))))
11410 (forward-line 1) 11612 (forward-line 1)
11411 (setq sig-list-i (verilog-signals-matching-dir-re 11613 (setq sig-list-i (verilog-signals-edit-wire-reg
11412 (verilog-signals-matching-regexp sig-list-i regexp) 11614 (verilog-signals-matching-dir-re
11413 "input" direction-re) 11615 (verilog-signals-matching-regexp sig-list-i regexp)
11414 sig-list-o (verilog-signals-matching-dir-re 11616 "input" direction-re))
11415 (verilog-signals-matching-regexp sig-list-o regexp) 11617 sig-list-o (verilog-signals-edit-wire-reg
11416 "output" direction-re) 11618 (verilog-signals-matching-dir-re
11417 sig-list-io (verilog-signals-matching-dir-re 11619 (verilog-signals-matching-regexp sig-list-o regexp)
11418 (verilog-signals-matching-regexp sig-list-io regexp) 11620 "output" direction-re))
11419 "inout" direction-re) 11621 sig-list-io (verilog-signals-edit-wire-reg
11622 (verilog-signals-matching-dir-re
11623 (verilog-signals-matching-regexp sig-list-io regexp)
11624 "inout" direction-re))
11420 sig-list-if (verilog-signals-matching-dir-re 11625 sig-list-if (verilog-signals-matching-dir-re
11421 (verilog-signals-matching-regexp sig-list-if regexp) 11626 (verilog-signals-matching-regexp sig-list-if regexp)
11422 "interface" direction-re)) 11627 "interface" direction-re))
11423 (when v2k (verilog-repair-open-comma)) 11628 (when v2k (verilog-repair-open-comma))
11424 (when (or sig-list-i sig-list-o sig-list-io) 11629 (when (or sig-list-i sig-list-o sig-list-io)
11425 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n") 11630 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
11426 ;; Don't sort them so a upper AUTOINST will match the main module 11631 ;; Don't sort them so an upper AUTOINST will match the main module
11427 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t) 11632 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
11428 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t) 11633 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
11429 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t) 11634 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
@@ -11450,7 +11655,7 @@ Limitations:
11450 Module names must be resolvable to filenames. See `verilog-auto-inst'. 11655 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11451 11656
11452 Signals are not inserted in the same order as in the original module, 11657 Signals are not inserted in the same order as in the original module,
11453 though they will appear to be in the same order to a AUTOINST 11658 though they will appear to be in the same order to an AUTOINST
11454 instantiating either module. 11659 instantiating either module.
11455 11660
11456An example: 11661An example:
@@ -11501,7 +11706,7 @@ Limitations:
11501 Module names must be resolvable to filenames. See `verilog-auto-inst'. 11706 Module names must be resolvable to filenames. See `verilog-auto-inst'.
11502 11707
11503 Signals are not inserted in the same order as in the original module, 11708 Signals are not inserted in the same order as in the original module,
11504 though they will appear to be in the same order to a AUTOINST 11709 though they will appear to be in the same order to an AUTOINST
11505 instantiating either module. 11710 instantiating either module.
11506 11711
11507An example: 11712An example:
@@ -11624,7 +11829,7 @@ Limitations:
11624 11829
11625Constant signals: 11830Constant signals:
11626 AUTOSENSE cannot always determine if a `define is a constant or a signal 11831 AUTOSENSE cannot always determine if a `define is a constant or a signal
11627 (it could be in a include file for example). If a `define or other signal 11832 (it could be in an include file for example). If a `define or other signal
11628 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT 11833 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
11629 declaration anywhere in the module (parenthesis are required): 11834 declaration anywhere in the module (parenthesis are required):
11630 11835
@@ -11726,9 +11931,9 @@ begin/case/if statement and the AUTORESET comment are being reset manually
11726and should not be automatically reset. This includes omitting any signals 11931and should not be automatically reset. This includes omitting any signals
11727used on the right hand side of assignments. 11932used on the right hand side of assignments.
11728 11933
11729By default, AUTORESET will include the width of the signal in the autos, 11934By default, AUTORESET will include the width of the signal in the
11730this is a recent change. To control this behavior, see 11935autos, SystemVerilog designs may want to change this. To control
11731`verilog-auto-reset-widths'. 11936this behavior, see `verilog-auto-reset-widths'.
11732 11937
11733AUTORESET ties signals to deasserted, which is presumed to be zero. 11938AUTORESET ties signals to deasserted, which is presumed to be zero.
11734Signals that match `verilog-active-low-regexp' will be deasserted by tying 11939Signals that match `verilog-active-low-regexp' will be deasserted by tying
@@ -11806,7 +12011,7 @@ Typing \\[verilog-auto] will make this into:
11806 (if (assoc (verilog-sig-name sig) dly-list) 12011 (if (assoc (verilog-sig-name sig) dly-list)
11807 (concat " <= " verilog-assignment-delay) 12012 (concat " <= " verilog-assignment-delay)
11808 " = ") 12013 " = ")
11809 (verilog-sig-tieoff sig (not verilog-auto-reset-widths)) 12014 (verilog-sig-tieoff sig)
11810 ";\n") 12015 ";\n")
11811 (setq sig-list (cdr sig-list)))) 12016 (setq sig-list (cdr sig-list))))
11812 (verilog-insert-indent "// End of automatics"))))) 12017 (verilog-insert-indent "// End of automatics")))))
@@ -11831,6 +12036,9 @@ You can add signals you do not want included in AUTOTIEOFF with
11831`verilog-auto-wire-type' may be used to change the datatype of 12036`verilog-auto-wire-type' may be used to change the datatype of
11832the declarations. 12037the declarations.
11833 12038
12039`verilog-auto-reset-widths' may be used to change how the tieoff
12040value's width is generated.
12041
11834An example of making a stub for another module: 12042An example of making a stub for another module:
11835 12043
11836 module ExampStub (/*AUTOINST*/); 12044 module ExampStub (/*AUTOINST*/);
@@ -11893,6 +12101,73 @@ Typing \\[verilog-auto] will make this into:
11893 (setq sig-list (cdr sig-list)))) 12101 (setq sig-list (cdr sig-list))))
11894 (verilog-insert-indent "// End of automatics\n"))))) 12102 (verilog-insert-indent "// End of automatics\n")))))
11895 12103
12104(defun verilog-auto-undef ()
12105 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
12106Take any `defines since the last AUTOUNDEF in the current file
12107and create `undefs for them. This is used to insure that
12108file-local defines do not polute the global `define name space.
12109
12110Limitations:
12111 AUTOUNDEF presumes any identifier following `define is the
12112 name of a define. Any `ifdefs are ignored.
12113
12114 AUTOUNDEF suppresses creating an `undef for any define that was
12115 `undefed before the AUTOUNDEF. This may be used to work around
12116 the ignoring of `ifdefs as shown below.
12117
12118An example:
12119
12120 `define XX_FOO
12121 `define M_BAR(x)
12122 `define M_BAZ
12123 ...
12124 `ifdef NEVER
12125 `undef M_BAZ // Emacs will see this and not `undef M_BAZ
12126 `endif
12127 ...
12128 /*AUTOUNDEF*/
12129
12130Typing \\[verilog-auto] will make this into:
12131
12132 ...
12133 /*AUTOUNDEF*/
12134 // Beginning of automatic undefs
12135 `undef XX_FOO
12136 `undef M_BAR
12137 // End of automatics
12138
12139You may also provide an optional regular expression, in which case only
12140defines the regular expression will be undefed."
12141 (save-excursion
12142 (let* ((params (verilog-read-auto-params 0 1))
12143 (regexp (nth 0 params))
12144 (indent-pt (current-indentation))
12145 (end-pt (point))
12146 defs def)
12147 (save-excursion
12148 ;; Scan from beginnng of file, or last AUTOUNDEF
12149 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
12150 (goto-char (point-min)))
12151 (while (verilog-re-search-forward-quick
12152 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
12153 (cond ((equal (match-string-no-properties 1) "define")
12154 (setq def (match-string-no-properties 2))
12155 (when (and (or (not regexp)
12156 (string-match regexp def))
12157 (not (member def defs))) ;; delete-dups not in 21.1
12158 (setq defs (cons def defs))))
12159 (t
12160 (setq defs (delete (match-string-no-properties 2) defs))))))
12161 ;; Insert
12162 (setq defs (sort defs 'string<))
12163 (when defs
12164 (forward-line 1)
12165 (verilog-insert-indent "// Beginning of automatic undefs\n")
12166 (while defs
12167 (verilog-insert-indent "`undef " (car defs) "\n")
12168 (setq defs (cdr defs)))
12169 (verilog-insert-indent "// End of automatics\n")))))
12170
11896(defun verilog-auto-unused () 12171(defun verilog-auto-unused ()
11897 "Expand AUTOUNUSED statements, as part of \\[verilog-auto]. 12172 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
11898Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused 12173Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
@@ -11981,17 +12256,17 @@ Remove user provided prefix ELIM-REGEXP."
11981 12256
11982(defun verilog-auto-ascii-enum () 12257(defun verilog-auto-ascii-enum ()
11983 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto]. 12258 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
11984Create a register to contain the ASCII decode of a enumerated signal type. 12259Create a register to contain the ASCII decode of an enumerated signal type.
11985This will allow trace viewers to show the ASCII name of states. 12260This will allow trace viewers to show the ASCII name of states.
11986 12261
11987First, parameters are built into a enumeration using the synopsys enum 12262First, parameters are built into an enumeration using the synopsys enum
11988comment. The comment must be between the keyword and the symbol. 12263comment. The comment must be between the keyword and the symbol.
11989\(Annoying, but that's what Synopsys's dc_shell FSM reader requires.) 12264\(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
11990 12265
11991Next, registers which that enum applies to are also tagged with the same 12266Next, registers which that enum applies to are also tagged with the same
11992enum. 12267enum.
11993 12268
11994Finally, a AUTOASCIIENUM command is used. 12269Finally, an AUTOASCIIENUM command is used.
11995 12270
11996 The first parameter is the name of the signal to be decoded. 12271 The first parameter is the name of the signal to be decoded.
11997 12272
@@ -12001,17 +12276,19 @@ Finally, a AUTOASCIIENUM command is used.
12001 tell viewers like Dinotrace to display in ASCII format. 12276 tell viewers like Dinotrace to display in ASCII format.
12002 12277
12003 The third optional parameter is a string which will be removed 12278 The third optional parameter is a string which will be removed
12004 from the state names. It defaults to "" which removes nothing. 12279 from the state names. It defaults to \"\" which removes nothing.
12005 12280
12006 The fourth optional parameter is \"onehot\" to force one-hot 12281 The fourth optional parameter is \"onehot\" to force one-hot
12007 decoding. If unspecified, if and only if the first parameter 12282 decoding. If unspecified, if and only if the first parameter
12008 width is 2^(number of states in enum) and does NOT match the 12283 width is 2^(number of states in enum) and does NOT match the
12009 width of the enum, the signal is assumed to be a one hot 12284 width of the enum, the signal is assumed to be a one-hot
12010 decode. Otherwise, it's a normal encoded state vector. 12285 decode. Otherwise, it's a normal encoded state vector.
12011 12286
12012 `verilog-auto-wire-type' may be used to change the datatype of 12287 `verilog-auto-wire-type' may be used to change the datatype of
12013 the declarations. 12288 the declarations.
12014 12289
12290 \"auto enum\" may be used in place of \"synopsys enum\".
12291
12015An example: 12292An example:
12016 12293
12017 //== State enumeration 12294 //== State enumeration
@@ -12066,7 +12343,7 @@ Typing \\[verilog-auto] will make this into:
12066 (undecode-sig (or (assoc undecode-name sig-list-all) 12343 (undecode-sig (or (assoc undecode-name sig-list-all)
12067 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name))) 12344 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
12068 (undecode-enum (or (verilog-sig-enum undecode-sig) 12345 (undecode-enum (or (verilog-sig-enum undecode-sig)
12069 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name))) 12346 (error "%s: Signal %s does not have an enum tag" (verilog-point-text) undecode-name)))
12070 ;; 12347 ;;
12071 (enum-sigs (verilog-signals-not-in 12348 (enum-sigs (verilog-signals-not-in
12072 (or (verilog-signals-matching-enum sig-list-consts undecode-enum) 12349 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
@@ -12159,12 +12436,39 @@ being different from the final output's line numbering."
12159 (string-to-number (match-string 2))))) 12436 (string-to-number (match-string 2)))))
12160 t t)))) 12437 t t))))
12161 12438
12439(defun verilog-auto-template-lint ()
12440 "Check AUTO_TEMPLATEs for unused lines.
12441Enable with `verilog-auto-template-warn-unused'."
12442 (let ((name1 (or (buffer-file-name) (buffer-name))))
12443 (save-excursion
12444 (goto-char (point-min))
12445 (while (re-search-forward
12446 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
12447 (let* ((tpl-info (verilog-read-auto-template-middle))
12448 (tpl-list (aref tpl-info 1))
12449 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
12450 tpl-ass)
12451 (while tlines
12452 (setq tpl-ass (car tlines)
12453 tlines (cdr tlines))
12454 ;;;
12455 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ;; Not supported, no warning
12456 (not verilog-auto-template-hits)
12457 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
12458 verilog-auto-template-hits))
12459 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
12460 name1
12461 (+ (elt tpl-ass 3) ;; Template line number
12462 (count-lines (point-min) (point)))
12463 (elt tpl-ass 0) (elt tpl-ass 1))
12464 )))))))
12465
12162 12466
12163;; 12467;;
12164;; Auto top level 12468;; Auto top level
12165;; 12469;;
12166 12470
12167(defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg 12471(defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
12168 "Expand AUTO statements. 12472 "Expand AUTO statements.
12169Look for any /*AUTO...*/ commands in the code, as used in 12473Look for any /*AUTO...*/ commands in the code, as used in
12170instantiations or argument headers. Update the list of signals 12474instantiations or argument headers. Update the list of signals
@@ -12219,6 +12523,7 @@ Using \\[describe-function], see also:
12219 `verilog-auto-reset' for AUTORESET flop resets 12523 `verilog-auto-reset' for AUTORESET flop resets
12220 `verilog-auto-sense' for AUTOSENSE always sensitivity lists 12524 `verilog-auto-sense' for AUTOSENSE always sensitivity lists
12221 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs 12525 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
12526 `verilog-auto-undef' for AUTOUNDEF `undef of local `defines
12222 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts 12527 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
12223 `verilog-auto-wire' for AUTOWIRE instantiation wires 12528 `verilog-auto-wire' for AUTOWIRE instantiation wires
12224 12529
@@ -12232,21 +12537,15 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12232 (unless noninteractive (message "Updating AUTOs...")) 12537 (unless noninteractive (message "Updating AUTOs..."))
12233 (if (fboundp 'dinotrace-unannotate-all) 12538 (if (fboundp 'dinotrace-unannotate-all)
12234 (dinotrace-unannotate-all)) 12539 (dinotrace-unannotate-all))
12235 (let ((oldbuf (if (not (buffer-modified-p)) 12540 (verilog-save-font-mods
12236 (buffer-string))) 12541 (let ((oldbuf (if (not (buffer-modified-p))
12237 ;; Before version 20, match-string with font-lock returns a 12542 (buffer-string)))
12238 ;; vector that is not equal to the string. IE if on "input" 12543 ;; Cache directories; we don't write new files, so can't change
12239 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0))) 12544 (verilog-dir-cache-preserving t)
12240 (fontlocked (when (and (boundp 'font-lock-mode) 12545 ;; Cache current module
12241 font-lock-mode) 12546 (verilog-modi-cache-current-enable t)
12242 (font-lock-mode 0) 12547 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
12243 t)) 12548 verilog-modi-cache-current)
12244 ;; Cache directories; we don't write new files, so can't change
12245 (verilog-dir-cache-preserving t)
12246 ;; Cache current module
12247 (verilog-modi-cache-current-enable t)
12248 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
12249 verilog-modi-cache-current)
12250 (unwind-protect 12549 (unwind-protect
12251 ;; Disable change hooks for speed 12550 ;; Disable change hooks for speed
12252 ;; This let can't be part of above let; must restore 12551 ;; This let can't be part of above let; must restore
@@ -12257,6 +12556,8 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12257 ;; Wipe cache; otherwise if we AUTOed a block above this one, 12556 ;; Wipe cache; otherwise if we AUTOed a block above this one,
12258 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT 12557 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
12259 (setq verilog-modi-cache-list nil) 12558 (setq verilog-modi-cache-list nil)
12559 ;; Local state
12560 (setq verilog-auto-template-hits nil)
12260 ;; If we're not in verilog-mode, change syntax table so parsing works right 12561 ;; If we're not in verilog-mode, change syntax table so parsing works right
12261 (unless (eq major-mode `verilog-mode) (verilog-mode)) 12562 (unless (eq major-mode `verilog-mode) (verilog-mode))
12262 ;; Allow user to customize 12563 ;; Allow user to customize
@@ -12272,6 +12573,8 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12272 (when verilog-auto-read-includes 12573 (when verilog-auto-read-includes
12273 (verilog-read-includes) 12574 (verilog-read-includes)
12274 (verilog-read-defines nil nil t)) 12575 (verilog-read-defines nil nil t))
12576 ;; Setup variables due to SystemVerilog expansion
12577 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
12275 ;; This particular ordering is important 12578 ;; This particular ordering is important
12276 ;; INST: Lower modules correct, no internal dependencies, FIRST 12579 ;; INST: Lower modules correct, no internal dependencies, FIRST
12277 (verilog-preserve-modi-cache 12580 (verilog-preserve-modi-cache
@@ -12284,7 +12587,7 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12284 (verilog-inject-arg)) 12587 (verilog-inject-arg))
12285 ;; 12588 ;;
12286 ;; Do user inserts first, so their code can insert AUTOs 12589 ;; Do user inserts first, so their code can insert AUTOs
12287 ;; We may provide a AUTOINSERTLISPLAST if another cleanup pass is needed 12590 ;; We may provide an AUTOINSERTLISPLAST if another cleanup pass is needed
12288 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/" 12591 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
12289 'verilog-auto-insert-lisp) 12592 'verilog-auto-insert-lisp)
12290 ;; Expand instances before need the signals the instances input/output 12593 ;; Expand instances before need the signals the instances input/output
@@ -12313,6 +12616,8 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12313 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout) 12616 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
12314 ;; Then tie off those in/outs 12617 ;; Then tie off those in/outs
12315 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff) 12618 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
12619 ;; These can be anywhere after AUTOINSERTLISP
12620 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((\"[^\"]*\")\\)?\\*/" 'verilog-auto-undef)
12316 ;; Wires/regs must be after inputs/outputs 12621 ;; Wires/regs must be after inputs/outputs
12317 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic) 12622 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
12318 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire) 12623 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
@@ -12326,7 +12631,9 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12326 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg) 12631 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
12327 ;; Fix line numbers (comments only) 12632 ;; Fix line numbers (comments only)
12328 (when verilog-auto-inst-template-numbers 12633 (when verilog-auto-inst-template-numbers
12329 (verilog-auto-templated-rel)))) 12634 (verilog-auto-templated-rel))
12635 (when verilog-auto-template-warn-unused
12636 (verilog-auto-template-lint))))
12330 ;; 12637 ;;
12331 (verilog-run-hooks 'verilog-auto-hook) 12638 (verilog-run-hooks 'verilog-auto-hook)
12332 ;; 12639 ;;
@@ -12343,9 +12650,8 @@ Wilson Snyder (wsnyder@wsnyder.org)."
12343 ;; End of after-change protection 12650 ;; End of after-change protection
12344 ))) 12651 )))
12345 ;; Unwind forms 12652 ;; Unwind forms
12346 (progn 12653 ;; Currently handled in verilog-save-font-mods
12347 ;; Restore font-lock 12654 ))))
12348 (when fontlocked (font-lock-mode t))))))
12349 12655
12350 12656
12351;; 12657;;
@@ -12650,7 +12956,7 @@ and the case items."
12650(define-skeleton verilog-sk-def-reg 12956(define-skeleton verilog-sk-def-reg
12651 "Insert a reg definition." 12957 "Insert a reg definition."
12652 () 12958 ()
12653 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) ) 12959 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
12654 12960
12655(defun verilog-sk-define-signal () 12961(defun verilog-sk-define-signal ()
12656 "Insert a definition of signal under point at top of module." 12962 "Insert a definition of signal under point at top of module."
@@ -12914,9 +13220,12 @@ Files are checked based on `verilog-library-flags'."
12914 (concat "verilog-mode v" verilog-mode-version) 13220 (concat "verilog-mode v" verilog-mode-version)
12915 '( 13221 '(
12916 verilog-active-low-regexp 13222 verilog-active-low-regexp
13223 verilog-after-save-font-hook
12917 verilog-align-ifelse 13224 verilog-align-ifelse
12918 verilog-assignment-delay 13225 verilog-assignment-delay
12919 verilog-auto-arg-sort 13226 verilog-auto-arg-sort
13227 verilog-auto-declare-nettype
13228 verilog-auto-delete-trailing-whitespace
12920 verilog-auto-endcomments 13229 verilog-auto-endcomments
12921 verilog-auto-hook 13230 verilog-auto-hook
12922 verilog-auto-ignore-concat 13231 verilog-auto-ignore-concat
@@ -12925,23 +13234,32 @@ Files are checked based on `verilog-library-flags'."
12925 verilog-auto-input-ignore-regexp 13234 verilog-auto-input-ignore-regexp
12926 verilog-auto-inst-column 13235 verilog-auto-inst-column
12927 verilog-auto-inst-dot-name 13236 verilog-auto-inst-dot-name
13237 verilog-auto-inst-interfaced-ports
12928 verilog-auto-inst-param-value 13238 verilog-auto-inst-param-value
13239 verilog-auto-inst-sort
12929 verilog-auto-inst-template-numbers 13240 verilog-auto-inst-template-numbers
12930 verilog-auto-inst-vector 13241 verilog-auto-inst-vector
12931 verilog-auto-lineup 13242 verilog-auto-lineup
12932 verilog-auto-newline 13243 verilog-auto-newline
12933 verilog-auto-output-ignore-regexp 13244 verilog-auto-output-ignore-regexp
12934 verilog-auto-read-includes 13245 verilog-auto-read-includes
13246 verilog-auto-reset-blocking-in-non
12935 verilog-auto-reset-widths 13247 verilog-auto-reset-widths
12936 verilog-auto-save-policy 13248 verilog-auto-save-policy
12937 verilog-auto-sense-defines-constant 13249 verilog-auto-sense-defines-constant
12938 verilog-auto-sense-include-inputs 13250 verilog-auto-sense-include-inputs
12939 verilog-auto-star-expand 13251 verilog-auto-star-expand
12940 verilog-auto-star-save 13252 verilog-auto-star-save
13253 verilog-auto-template-warn-unused
13254 verilog-auto-tieoff-declaration
13255 verilog-auto-tieoff-ignore-regexp
12941 verilog-auto-unused-ignore-regexp 13256 verilog-auto-unused-ignore-regexp
13257 verilog-auto-wire-type
12942 verilog-before-auto-hook 13258 verilog-before-auto-hook
12943 verilog-before-delete-auto-hook 13259 verilog-before-delete-auto-hook
12944 verilog-before-getopt-flags-hook 13260 verilog-before-getopt-flags-hook
13261 verilog-before-save-font-hook
13262 verilog-cache-enabled
12945 verilog-case-indent 13263 verilog-case-indent
12946 verilog-cexp-indent 13264 verilog-cexp-indent
12947 verilog-compiler 13265 verilog-compiler
@@ -12949,6 +13267,8 @@ Files are checked based on `verilog-library-flags'."
12949 verilog-delete-auto-hook 13267 verilog-delete-auto-hook
12950 verilog-getopt-flags-hook 13268 verilog-getopt-flags-hook
12951 verilog-highlight-grouping-keywords 13269 verilog-highlight-grouping-keywords
13270 verilog-highlight-includes
13271 verilog-highlight-modules
12952 verilog-highlight-p1800-keywords 13272 verilog-highlight-p1800-keywords
12953 verilog-highlight-translate-off 13273 verilog-highlight-translate-off
12954 verilog-indent-begin-after-if 13274 verilog-indent-begin-after-if
@@ -12966,11 +13286,15 @@ Files are checked based on `verilog-library-flags'."
12966 verilog-linter 13286 verilog-linter
12967 verilog-minimum-comment-distance 13287 verilog-minimum-comment-distance
12968 verilog-mode-hook 13288 verilog-mode-hook
13289 verilog-mode-release-date
13290 verilog-mode-release-emacs
13291 verilog-mode-version
12969 verilog-preprocessor 13292 verilog-preprocessor
12970 verilog-simulator 13293 verilog-simulator
12971 verilog-tab-always-indent 13294 verilog-tab-always-indent
12972 verilog-tab-to-comment 13295 verilog-tab-to-comment
12973 verilog-typedef-regexp 13296 verilog-typedef-regexp
13297 verilog-warn-fatal
12974 ) 13298 )
12975 nil nil 13299 nil nil
12976 (concat "Hi Mac, 13300 (concat "Hi Mac,
diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index c8435c14ea2..07cb43b64a2 100644
--- a/lisp/progmodes/which-func.el
+++ b/lisp/progmodes/which-func.el
@@ -68,7 +68,7 @@
68 "String to display in the mode line when current function is unknown.") 68 "String to display in the mode line when current function is unknown.")
69 69
70(defgroup which-func nil 70(defgroup which-func nil
71 "Mode to display the current function name in the modeline." 71 "Display the current function name in the modeline."
72 :group 'tools 72 :group 'tools
73 :version "20.3") 73 :version "20.3")
74 74
@@ -179,7 +179,9 @@ and you want to simplify them for the mode line
179(defvar which-func-table (make-hash-table :test 'eq :weakness 'key)) 179(defvar which-func-table (make-hash-table :test 'eq :weakness 'key))
180 180
181(defconst which-func-current 181(defconst which-func-current
182 '(:eval (gethash (selected-window) which-func-table which-func-unknown))) 182 '(:eval (replace-regexp-in-string
183 "%" "%%"
184 (gethash (selected-window) which-func-table which-func-unknown))))
183;;;###autoload (put 'which-func-current 'risky-local-variable t) 185;;;###autoload (put 'which-func-current 'risky-local-variable t)
184 186
185(defvar which-func-mode nil 187(defvar which-func-mode nil
@@ -207,7 +209,8 @@ It creates the Imenu index for the buffer, if necessary."
207 (setq imenu--index-alist 209 (setq imenu--index-alist
208 (save-excursion (funcall imenu-create-index-function)))) 210 (save-excursion (funcall imenu-create-index-function))))
209 (error 211 (error
210 (unless (equal err '(error "This buffer cannot use `imenu-default-create-index-function'")) 212 (unless (equal err
213 '(user-error "This buffer cannot use `imenu-default-create-index-function'"))
211 (message "which-func-ff-hook error: %S" err)) 214 (message "which-func-ff-hook error: %S" err))
212 (setq which-func-mode nil)))) 215 (setq which-func-mode nil))))
213 216