comparison lisp/progmodes/verilog-mode.el @ 111870:b47e85affa59

Derive from prog-mode, use derived-mode-p, and fix up various minor style issues in lisp/progmodes. * lisp/progmodes/vhdl-mode.el (vhdl-write-file-hooks-init) (vhdl-hs-minor-mode, vhdl-ps-print-init): Fix make-local-variable -> make-local-hook. * lisp/progmodes/sh-script.el (sh-require-final-newline): Remove. (sh-set-shell): Don't set require-final-newline since it's already done by prog-mode. * lisp/progmodes/modula2.el (m2-mode): Don't make m2-end-comment-column since we never set it. * lisp/progmodes/ebrowse.el (ebrowse-set-tree-indentation): Use read-string and standard prompt. * lisp/progmodes/dcl-mode.el (dcl-mode-map): Move init into declaration. * lisp/progmodes/meta-mode.el (meta-mode-abbrev-table): Merge init and decl. (meta-common-mode-syntax-table): Rename from meta-mode-syntax-table. (meta-common-mode-map): Rename from meta-mode-map. Remove C-m binding, which is a user preference, not mode specific. (meta-common-mode): New major mode; replace meta-common-initialization. * lisp/progmodes/js.el (js-mode): Call syntax-propertize rather than messing around with font-lock. * lisp/progmodes/etags.el (select-tags-table-mode): Derive from special-mode. * lisp/progmodes/octave-mod.el (octave-mode): * lisp/progmodes/gdb-mi.el (gdb-inferior-io-mode, gdb-threads-mode) (gdb-memory-mode, gdb-disassembly-mode, gdb-breakpoints-mode) (gdb-frames-mode, gdb-locals-mode, gdb-registers-mode): Let define-derived-mode do its job. * lisp/progmodes/cpp.el (cpp-edit-mode-map): Move initialization into declaration. (cpp-edit-mode): Use define-derived-mode. (cpp-edit-load): Use derived-mode-p. * lisp/progmodes/mixal-mode.el (mixal-mode): * lisp/progmodes/f90.el (f90-mode): * lisp/progmodes/cfengine.el (cfengine-mode): Don't bother setting require-final-newline since prog-mode does it already. * lisp/progmodes/cc-cmds.el (c-update-modeline): Use match-string. * lisp/progmodes/asm-mode.el (asm-mode-map): Fix menu setup. * lisp/progmodes/antlr-mode.el: Require cc-mode upfront. (antlr-mode-syntax-table, antlr-action-syntax-table): Initialize in the declaration. (antlr-directory-dependencies, antlr-show-makefile-rules): Use derived-mode-p. (antlr-language-option): Don't assume point-min==1. (antlr-mode): Use define-derived-mode. * lisp/progmodes/ada-mode.el: Use derived-mode-p. (ada-mode): Use define-derived-mode. Use hack-local-variables-hook. * lisp/progmodes/vhdl-mode.el (vhdl-mode): * lisp/progmodes/verilog-mode.el (verilog-mode): * lisp/progmodes/vera-mode.el (vera-mode): * lisp/progmodes/sql.el (sql-mode): * lisp/progmodes/scheme.el (scheme-mode): * lisp/progmodes/perl-mode.el (perl-mode): * lisp/progmodes/octave-inf.el (inferior-octave-mode): * lisp/progmodes/autoconf.el (autoconf-mode): * lisp/progmodes/m4-mode.el (m4-mode): * lisp/progmodes/inf-lisp.el (inferior-lisp-mode): * lisp/progmodes/idlwave.el (idlwave-mode): * lisp/progmodes/icon.el (icon-mode): * lisp/progmodes/idlw-help.el (idlwave-help-mode): * lisp/progmodes/dcl-mode.el (dcl-mode): * lisp/progmodes/idlw-shell.el (idlwave-shell-mode): * lisp/progmodes/ebrowse.el (ebrowse-tree-mode, ebrowse-electric-list-mode) (ebrowse-member-mode, ebrowse-electric-position-mode): Use define-derived-mode. * lisp/progmodes/xscheme.el (xscheme-start) (local-set-scheme-interaction-buffer, scheme-interaction-mode): * lisp/progmodes/which-func.el (which-function): * lisp/progmodes/vhdl-mode.el (vhdl-set-style): * lisp/progmodes/verilog-mode.el (verilog-set-compile-command) (verilog-modify-compile-command, verilog-error-regexp-add-xemacs) (verilog-set-define, verilog-auto-reeval-locals): * lisp/progmodes/sql.el (sql-product-font-lock, sql-interactive-mode): * lisp/progmodes/simula.el (simula-mode): * lisp/progmodes/scheme.el (scheme-mode-variables, dsssl-mode): * lisp/progmodes/python.el (python-check, python-mode): * lisp/progmodes/prolog.el (prolog-mode-variables): * lisp/progmodes/gud.el (gud-tooltip-activate-mouse-motions): * lisp/progmodes/ebrowse.el (ebrowse-view-file-other-frame): * lisp/progmodes/delphi.el (delphi-mode): * lisp/progmodes/cc-styles.el (c-setup-paragraph-variables): * lisp/progmodes/cc-mode.el (c-basic-common-init, c-common-init) (c-font-lock-init): Move make-local-variable to their setq. * lisp/progmodes/xscheme.el (exit-scheme-interaction-mode) (xscheme-enter-interaction-mode, xscheme-enter-debugger-mode) (xscheme-debugger-mode-p, xscheme-send-string-1): * lisp/progmodes/tcl.el (inferior-tcl-proc, tcl-current-word) (tcl-load-file, tcl-restart-with-file): * lisp/progmodes/ps-mode.el (ps-run-running): * lisp/progmodes/gdb-mi.el (gud-watch, gdb-mouse-set-clear-breakpoint): * lisp/progmodes/js.el (js--get-all-known-symbols): * lisp/progmodes/inf-lisp.el (inferior-lisp-proc): * lisp/progmodes/idlwave.el (idlwave-beginning-of-statement) (idlwave-template, idlwave-update-buffer-routine-info) (idlwave-update-current-buffer-info) (idlwave-get-routine-info-from-buffers, idlwave-choose) (idlwave-scan-class-info, idlwave-fix-keywords) (idlwave-list-buffer-load-path-shadows): * lisp/progmodes/idlw-toolbar.el (idlwave-toolbar, idlwave-toolbar-add) (idlwave-toolbar-remove): * lisp/progmodes/idlw-shell.el (idlwave-shell-save-and-action) (idlwave-shell-file-name, idlwave-shell-electric-debug-all-off) (idlwave-shell-menu-def): * lisp/progmodes/idlw-complete-structtag.el (idlwave-prepare-structure-tag-completion): * lisp/progmodes/gud.el (gud-set-buffer): * lisp/progmodes/f90.el (f90-backslash-not-special): * lisp/progmodes/delphi.el (delphi-find-unit): Use derived-mode-p.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 10 Dec 2010 15:00:25 -0500
parents 132f2dfd549f
children 417b1e4d63cd
comparison
equal deleted inserted replaced
111869:2b8673bc05c8 111870:b47e85affa59
1531 portion, will be substituted." 1531 portion, will be substituted."
1532 (interactive) 1532 (interactive)
1533 (cond 1533 (cond
1534 ((or (file-exists-p "makefile") ;If there is a makefile, use it 1534 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1535 (file-exists-p "Makefile")) 1535 (file-exists-p "Makefile"))
1536 (make-local-variable 'compile-command) 1536 (set (make-local-variable 'compile-command) "make "))
1537 (setq compile-command "make "))
1538 (t 1537 (t
1539 (make-local-variable 'compile-command) 1538 (set (make-local-variable 'compile-command)
1540 (setq compile-command 1539 (if verilog-tool
1541 (if verilog-tool 1540 (if (string-match "%s" (eval verilog-tool))
1542 (if (string-match "%s" (eval verilog-tool)) 1541 (format (eval verilog-tool) (or buffer-file-name ""))
1543 (format (eval verilog-tool) (or buffer-file-name "")) 1542 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1544 (concat (eval verilog-tool) " " (or buffer-file-name ""))) 1543 ""))))
1545 ""))))
1546 (verilog-modify-compile-command)) 1544 (verilog-modify-compile-command))
1547 1545
1548 (defun verilog-expand-command (command) 1546 (defun verilog-expand-command (command)
1549 "Replace meta-information in COMMAND and return it. 1547 "Replace meta-information in COMMAND and return it.
1550 Where __FLAGS__ appears in the string `verilog-current-flags' 1548 Where __FLAGS__ appears in the string `verilog-current-flags'
1564 (defun verilog-modify-compile-command () 1562 (defun verilog-modify-compile-command ()
1565 "Update `compile-command' using `verilog-expand-command'." 1563 "Update `compile-command' using `verilog-expand-command'."
1566 (when (and 1564 (when (and
1567 (stringp compile-command) 1565 (stringp compile-command)
1568 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command)) 1566 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1569 (make-local-variable 'compile-command) 1567 (set (make-local-variable 'compile-command)
1570 (setq compile-command (verilog-expand-command compile-command)))) 1568 (verilog-expand-command compile-command))))
1571 1569
1572 (if (featurep 'xemacs) 1570 (if (featurep 'xemacs)
1573 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling. 1571 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1574 (defun verilog-error-regexp-add-xemacs () 1572 (defun verilog-error-regexp-add-xemacs ()
1575 "Teach XEmacs about verilog errors. 1573 "Teach XEmacs about verilog errors.
1586 (setcdr compilation-error-regexp-alist-alist 1584 (setcdr compilation-error-regexp-alist-alist
1587 (cons verilog-error-regexp-xemacs-alist 1585 (cons verilog-error-regexp-xemacs-alist
1588 (cdr compilation-error-regexp-alist-alist))))) 1586 (cdr compilation-error-regexp-alist-alist)))))
1589 (if (boundp 'compilation-font-lock-keywords) 1587 (if (boundp 'compilation-font-lock-keywords)
1590 (progn 1588 (progn
1591 (make-local-variable 'compilation-font-lock-keywords) 1589 (set (make-local-variable 'compilation-font-lock-keywords)
1592 (setq compilation-font-lock-keywords verilog-error-font-lock-keywords) 1590 verilog-error-font-lock-keywords)
1593 (font-lock-set-defaults))) 1591 (font-lock-set-defaults)))
1594 ;; Need to re-run compilation-error-regexp builder 1592 ;; Need to re-run compilation-error-regexp builder
1595 (if (fboundp 'compilation-build-compilation-error-regexp-alist) 1593 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1596 (compilation-build-compilation-error-regexp-alist)) 1594 (compilation-build-compilation-error-regexp-alist))
1597 )) 1595 ))
2973 ;; 2971 ;;
2974 ;; Mode 2972 ;; Mode
2975 ;; 2973 ;;
2976 (defvar verilog-which-tool 1) 2974 (defvar verilog-which-tool 1)
2977 ;;;###autoload 2975 ;;;###autoload
2978 (defun verilog-mode () 2976 (define-derived-mode verilog-mode prog-mode "Verilog"
2979 "Major mode for editing Verilog code. 2977 "Major mode for editing Verilog code.
2980 \\<verilog-mode-map> 2978 \\<verilog-mode-map>
2981 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how 2979 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
2982 AUTOs can improve coding efficiency. 2980 AUTOs can improve coding efficiency.
2983 2981
3101 3099
3102 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings]. 3100 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3103 Key bindings specific to `verilog-mode-map' are: 3101 Key bindings specific to `verilog-mode-map' are:
3104 3102
3105 \\{verilog-mode-map}" 3103 \\{verilog-mode-map}"
3106 (interactive) 3104 :abbrev-table verilog-mode-abbrev-table
3107 (kill-all-local-variables)
3108 (use-local-map verilog-mode-map)
3109 (setq major-mode 'verilog-mode)
3110 (setq mode-name "Verilog")
3111 (setq local-abbrev-table verilog-mode-abbrev-table)
3112 (set (make-local-variable 'beginning-of-defun-function) 3105 (set (make-local-variable 'beginning-of-defun-function)
3113 'verilog-beg-of-defun) 3106 'verilog-beg-of-defun)
3114 (set (make-local-variable 'end-of-defun-function) 3107 (set (make-local-variable 'end-of-defun-function)
3115 'verilog-end-of-defun) 3108 'verilog-end-of-defun)
3116 (set-syntax-table verilog-mode-syntax-table) 3109 (set-syntax-table verilog-mode-syntax-table)
3117 (make-local-variable 'indent-line-function) 3110 (set (make-local-variable 'indent-line-function)
3118 (setq indent-line-function 'verilog-indent-line-relative) 3111 #'verilog-indent-line-relative)
3119 (setq comment-indent-function 'verilog-comment-indent) 3112 (setq comment-indent-function 'verilog-comment-indent)
3120 (make-local-variable 'parse-sexp-ignore-comments) 3113 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3121 (setq parse-sexp-ignore-comments nil) 3114
3122 (make-local-variable 'comment-start) 3115 (set (make-local-variable 'comment-start) "// ")
3123 (make-local-variable 'comment-end) 3116 (set (make-local-variable 'comment-end) "")
3124 (make-local-variable 'comment-multi-line) 3117 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3125 (make-local-variable 'comment-start-skip) 3118 (set (make-local-variable 'comment-multi-line) nil)
3126 (setq comment-start "// "
3127 comment-end ""
3128 comment-start-skip "/\\*+ *\\|// *"
3129 comment-multi-line nil)
3130 ;; Set up for compilation 3119 ;; Set up for compilation
3131 (setq verilog-which-tool 1) 3120 (setq verilog-which-tool 1)
3132 (setq verilog-tool 'verilog-linter) 3121 (setq verilog-tool 'verilog-linter)
3133 (verilog-set-compile-command) 3122 (verilog-set-compile-command)
3134 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables 3123 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
3164 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t) 3153 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3165 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs 3154 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3166 (add-hook 'after-change-functions 'verilog-highlight-region t t)) 3155 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3167 3156
3168 ;; Tell imenu how to handle Verilog. 3157 ;; Tell imenu how to handle Verilog.
3169 (make-local-variable 'imenu-generic-expression) 3158 (set (make-local-variable 'imenu-generic-expression)
3170 (setq imenu-generic-expression verilog-imenu-generic-expression) 3159 verilog-imenu-generic-expression)
3171 ;; Tell which-func-modes that imenu knows about verilog 3160 ;; Tell which-func-modes that imenu knows about verilog
3172 (when (boundp 'which-function-modes) 3161 (when (boundp 'which-function-modes)
3173 (add-to-list 'which-func-modes 'verilog-mode)) 3162 (add-to-list 'which-func-modes 'verilog-mode))
3174 ;; hideshow support 3163 ;; hideshow support
3175 (when (boundp 'hs-special-modes-alist) 3164 (when (boundp 'hs-special-modes-alist)
3178 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil 3167 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3179 verilog-forward-sexp-function) 3168 verilog-forward-sexp-function)
3180 hs-special-modes-alist)))) 3169 hs-special-modes-alist))))
3181 3170
3182 ;; Stuff for autos 3171 ;; Stuff for autos
3183 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local 3172 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local))
3184 (run-hooks 'verilog-mode-hook))
3185 3173
3186 3174
3187 ;; 3175 ;;
3188 ;; Electric functions 3176 ;; Electric functions
3189 ;; 3177 ;;
8040 (if (equal defvalue "") "1" defvalue))) 8028 (if (equal defvalue "") "1" defvalue)))
8041 (if enumname 8029 (if enumname
8042 (let ((enumvar (intern (concat "venum-" enumname)))) 8030 (let ((enumvar (intern (concat "venum-" enumname))))
8043 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) 8031 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
8044 (unless (boundp enumvar) (set enumvar nil)) 8032 (unless (boundp enumvar) (set enumvar nil))
8045 (make-local-variable enumvar) 8033 (add-to-list (make-local-variable enumvar) defname)))))
8046 (add-to-list enumvar defname)))))
8047 8034
8048 (defun verilog-read-defines (&optional filename recurse subcall) 8035 (defun verilog-read-defines (&optional filename recurse subcall)
8049 "Read `defines and parameters for the current file, or optional FILENAME. 8036 "Read `defines and parameters for the current file, or optional FILENAME.
8050 If the filename is provided, `verilog-library-flags' will be used to 8037 If the filename is provided, `verilog-library-flags' will be used to
8051 resolve it. If optional RECURSE is non-nil, recurse through `includes. 8038 resolve it. If optional RECURSE is non-nil, recurse through `includes.
9347 ""))) 9334 "")))
9348 9335
9349 (defun verilog-auto-reeval-locals (&optional force) 9336 (defun verilog-auto-reeval-locals (&optional force)
9350 "Read file local variable segment at bottom of file if it has changed. 9337 "Read file local variable segment at bottom of file if it has changed.
9351 If FORCE, always reread it." 9338 If FORCE, always reread it."
9352 (make-local-variable 'verilog-auto-last-file-locals)
9353 (let ((curlocal (verilog-auto-read-locals))) 9339 (let ((curlocal (verilog-auto-read-locals)))
9354 (when (or force (not (equal verilog-auto-last-file-locals curlocal))) 9340 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
9355 (setq verilog-auto-last-file-locals curlocal) 9341 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
9356 ;; Note this may cause this function to be recursively invoked, 9342 ;; Note this may cause this function to be recursively invoked,
9357 ;; because hack-local-variables may call (verilog-mode) 9343 ;; because hack-local-variables may call (verilog-mode)
9358 ;; The above when statement will prevent it from recursing forever. 9344 ;; The above when statement will prevent it from recursing forever.
9359 (hack-local-variables) 9345 (hack-local-variables)
9360 t))) 9346 t)))