Fix indentation/fontification of Java enum with "implements"/generic.
[bpt/emacs.git] / lisp / progmodes / m4-mode.el
index c22a1f0..4ba2ae1 100644 (file)
@@ -1,7 +1,6 @@
 ;;; m4-mode.el --- m4 code editing commands for Emacs
 
-;; Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1996-1997, 2001-2013 Free Software Foundation, Inc.
 
 ;; Author: Andrew Csillag <drew_csillag@geocities.com>
 ;; Maintainer: Andrew Csillag <drew_csillag@geocities.com>
@@ -9,10 +8,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
   :prefix "m4-"
   :group 'languages)
 
-(defcustom m4-program
-  (cond
-   ((file-exists-p "/usr/local/bin/m4") "/usr/local/bin/m4")
-   ((file-exists-p "/usr/bin/m4") "/usr/bin/m4")
-   ((file-exists-p "/bin/m4") "/bin/m4")
-   ((file-exists-p "/usr/ccs/bin/m4") "/usr/ccs/bin/m4")
-   ( t "m4")
-   )
-  "File name of the m4 executable."
+(defcustom m4-program "m4"
+  "File name of the m4 executable.
+If m4 is not in your PATH, set this to an absolute file name."
+  :version "24.4"
   :type 'file
   :group 'm4)
 
   "Default font-lock-keywords for `m4 mode'.")
 
 (defcustom m4-mode-hook nil
-  "*Hook called by `m4-mode'."
+  "Hook called by `m4-mode'."
   :type 'hook
   :group 'm4)
 
 ;;this may still need some work
-(defvar m4-mode-syntax-table nil
+(defvar m4-mode-syntax-table
+  (let ((table (make-syntax-table)))
+    (modify-syntax-entry ?` "('" table)
+    (modify-syntax-entry ?' ")`" table)
+    (modify-syntax-entry ?# "<\n" table)
+    (modify-syntax-entry ?\n ">#" table)
+    (modify-syntax-entry ?{  "_" table)
+    (modify-syntax-entry ?}  "_" table)
+    ;; FIXME: This symbol syntax for underscore looks OK on its own, but it's
+    ;; odd that it should have the same syntax as { and } are these really
+    ;; valid in m4 symbols?
+    (modify-syntax-entry ?_  "_" table)
+    ;; FIXME: These three chars with word syntax look wrong.
+    (modify-syntax-entry ?*  "w" table)
+    (modify-syntax-entry ?\"  "w" table)
+    (modify-syntax-entry ?\"  "w" table)
+    table)
   "Syntax table used while in `m4-mode'.")
-(setq m4-mode-syntax-table (make-syntax-table))
-(modify-syntax-entry ?` "('" m4-mode-syntax-table)
-(modify-syntax-entry ?' ")`" m4-mode-syntax-table)
-(modify-syntax-entry ?# "<\n" m4-mode-syntax-table)
-(modify-syntax-entry ?\n ">#" m4-mode-syntax-table)
-(modify-syntax-entry ?{  "_" m4-mode-syntax-table)
-(modify-syntax-entry ?}  "_" m4-mode-syntax-table)
-(modify-syntax-entry ?*  "w" m4-mode-syntax-table)
-(modify-syntax-entry ?_  "w" m4-mode-syntax-table)
-(modify-syntax-entry ?\"  "w" m4-mode-syntax-table)
-(modify-syntax-entry ?\"  "w" m4-mode-syntax-table)
 
 (defvar m4-mode-map
   (let ((map (make-sparse-keymap))
                  :help "Send contents of the current region to m4"))
     map))
 
-(defvar m4-mode-abbrev-table nil
-  "Abbrev table used while in `m4-mode'.")
-
-(unless m4-mode-abbrev-table
-  (define-abbrev-table 'm4-mode-abbrev-table ()))
-
 (defun m4-m4-buffer ()
   "Send contents of the current buffer to m4."
   (interactive)
    "*m4-output*" nil)
   (switch-to-buffer-other-window "*m4-output*"))
 
+(defun m4-current-defun-name ()
+  "Return the name of the M4 function at point, or nil."
+  (save-excursion
+    (if (re-search-backward
+        "^\\(\\(m4_\\)?define\\|A._DEFUN\\)(\\[?\\([A-Za-z0-9_]+\\)" nil t)
+       (match-string-no-properties 3))))
+
 ;;;###autoload
-(defun m4-mode ()
-  "A major mode to edit m4 macro files.
-\\{m4-mode-map}
-"
-  (interactive)
-  (kill-all-local-variables)
-  (use-local-map m4-mode-map)
-
-  (make-local-variable 'comment-start)
-  (setq comment-start "#")
-  (make-local-variable 'parse-sexp-ignore-comments)
-  (setq parse-sexp-ignore-comments t)
-  (setq local-abbrev-table m4-mode-abbrev-table)
-
-  (make-local-variable 'font-lock-defaults)
-  (setq major-mode 'm4-mode
-       mode-name "m4"
-       font-lock-defaults '(m4-font-lock-keywords nil)
-       )
-  (set-syntax-table m4-mode-syntax-table)
-  (run-mode-hooks 'm4-mode-hook))
+(define-derived-mode m4-mode prog-mode "m4"
+  "A major mode to edit m4 macro files."
+  (setq-local comment-start "#")
+  (setq-local parse-sexp-ignore-comments t)
+  (setq-local add-log-current-defun-function #'m4-current-defun-name)
+  (setq font-lock-defaults '(m4-font-lock-keywords nil)))
 
 (provide 'm4-mode)
 ;;stuff to play with for debugging
 ;;;              "m4_syscmd" "m4_sysval" "m4_traceoff" "m4_traceon" "m4_translit"
 ;;;              "m4_m4_undefine" "m4_undivert"))
 
-;; arch-tag: 87811d86-94c1-474b-9666-587f6da74af1
 ;;; m4-mode.el ends here