;; You can also send in new modes; if the file types a reasonably common,
;; we would like to install them.
;;
+;; DEFAULT GENERIC MODE:
+;;
+;; This file provides a hook which automatically puts a file into
+;; `default-generic-mode' if the first few lines of a file in
+;; fundamental mode start with a hash comment character. To disable
+;; this functionality, set the variable `generic-use-find-file-hook'
+;; to nil BEFORE loading generic-x. See the variables
+;; `generic-lines-to-scan' and `generic-find-file-regexp' for
+;; customization options.
+;;
;; PROBLEMS WHEN USED WITH FOLDING MODE:
;;
;; [The following relates to the obsolete selective-display technique.
(require 'font-lock)
(defgroup generic-x nil
- "Extra modes for generic mode."
+ "A collection of generic modes."
:prefix "generic-"
- :group 'generic
+ :group 'data
:version "20.3")
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Default-Generic mode
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defcustom generic-use-find-file-hook t
+ "*If non-nil, add a hook to enter `default-generic-mode' automatically.
+This is done if the first few lines of a file in fundamental mode
+start with a hash comment character."
+ :group 'generic-x
+ :type 'boolean)
+
+(defcustom generic-lines-to-scan 3
+ "*Number of lines that `generic-mode-find-file-hook' looks at.
+Relevant when deciding whether to enter Default-Generic mode automatically.
+This variable should be set to a small positive number."
+ :group 'generic-x
+ :type 'integer)
+
+(defcustom generic-find-file-regexp "^#"
+ "*Regular expression used by `generic-mode-find-file-hook'.
+Files in fundamental mode whose first few lines contain a match
+for this regexp, should be put into Default-Generic mode instead.
+The number of lines tested for the matches is specified by the
+value of the variable `generic-lines-to-scan', which see."
+ :group 'generic-x
+ :type 'regexp)
+
+(defcustom generic-ignore-files-regexp "[Tt][Aa][Gg][Ss]\\'"
+ "*Regular expression used by `generic-mode-find-file-hook'.
+Files whose names match this regular expression should not be put
+into Default-Generic mode, even if they have lines which match
+the regexp in `generic-find-file-regexp'. If the value is nil,
+`generic-mode-find-file-hook' does not check the file names."
+ :group 'generic-x
+ :type '(choice (const :tag "Don't check file names" nil) regexp))
+
+;; This generic mode is always defined
+(define-generic-mode default-generic-mode (list ?#) nil nil nil nil :group 'generic)
+
+;; A more general solution would allow us to enter generic-mode for
+;; *any* comment character, but would require us to synthesize a new
+;; generic-mode on the fly. I think this gives us most of what we
+;; want.
+(defun generic-mode-find-file-hook ()
+ "Hook function to enter Default-Generic mode automatically.
+
+Done if the first few lines of a file in Fundamental mode start
+with a match for the regexp in `generic-find-file-regexp', unless
+the file's name matches the regexp which is the value of the
+variable `generic-ignore-files-regexp'.
+
+This hook will be installed if the variable
+`generic-use-find-file-hook' is non-nil. The variable
+`generic-lines-to-scan' determines the number of lines to look at."
+ (when (and (eq major-mode 'fundamental-mode)
+ (or (null generic-ignore-files-regexp)
+ (not (string-match
+ generic-ignore-files-regexp
+ (file-name-sans-versions buffer-file-name)))))
+ (save-excursion
+ (goto-char (point-min))
+ (when (re-search-forward generic-find-file-regexp
+ (save-excursion
+ (forward-line generic-lines-to-scan)
+ (point)) t)
+ (goto-char (point-min))
+ (default-generic-mode)))))
+
+(and generic-use-find-file-hook
+ (add-hook 'find-file-hook 'generic-mode-find-file-hook))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Other Generic modes
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
(defcustom generic-extras-enable-list nil
"*List of generic modes to enable by default.
Each entry in the list should be a symbol. The variables
etc-fstab-generic-mode)
generic-extras-enable-list)))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Generic-modes
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
;;; Apache
(when (memq 'apache-conf-generic-mode generic-extras-enable-list)
'((nil "^\\([-A-Za-z0-9_]+\\)" 1)
("*Directories*" "^\\s-*<Directory\\s-*\\([^>]+\\)>" 1)
("*Locations*" "^\\s-*<Location\\s-*\\([^>]+\\)>" 1))))))
- "Generic mode for Apache or HTTPD configuration files."))
+ "Generic mode for Apache or HTTPD configuration files."
+ :group 'generic-x))
(when (memq 'apache-log-generic-mode generic-extras-enable-list)
(2 font-lock-variable-name-face)))
'("access_log\\'")
nil
- "Mode for Apache log files"))
+ "Mode for Apache log files"
+ :group 'generic-x))
;;; Samba
(when (memq 'samba-generic-mode generic-extras-enable-list)
(2 font-lock-type-face)))
'("smb\\.conf\\'")
'(generic-bracket-support)
- "Generic mode for Samba configuration files."))
+ "Generic mode for Samba configuration files."
+ :group 'generic-x))
;;; Fvwm
;; This is pretty basic. Also, modes for other window managers could
nil
'("\\.fvwmrc\\'" "\\.fvwm2rc\\'")
nil
- "Generic mode for FVWM configuration files."))
+ "Generic mode for FVWM configuration files."
+ :group 'generic-x))
;;; X Resource
;; I'm pretty sure I've seen an actual mode to do this, but I don't
'(("^\\([^:\n]+:\\)" 1 font-lock-variable-name-face))
'("\\.Xdefaults\\'" "\\.Xresources\\'" "\\.Xenvironment\\'" "\\.ad\\'")
nil
- "Generic mode for X Resource configuration files."))
+ "Generic mode for X Resource configuration files."
+ :group 'generic-x))
;;; Hosts
(when (memq 'hosts-generic-mode generic-extras-enable-list)
'(("\\([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\\)" 1 font-lock-constant-face))
'("[hH][oO][sS][tT][sS]\\'")
nil
- "Generic mode for HOSTS files."))
+ "Generic mode for HOSTS files."
+ :group 'generic-x))
;;; Windows INF files
(when (memq 'inf-generic-mode generic-extras-enable-list)
'(("^\\(\\[.*\\]\\)" 1 font-lock-constant-face))
'("\\.[iI][nN][fF]\\'")
'(generic-bracket-support)
- "Generic mode for MS-Windows INF files."))
+ "Generic mode for MS-Windows INF files."
+ :group 'generic-x))
;;; Windows INI files
;; Should define escape character as well!
(setq imenu-generic-expression
'((nil "^\\[\\(.*\\)\\]" 1)
("*Variables*" "^\\s-*\\([^=]+\\)\\s-*=" 1))))))
- "Generic mode for MS-Windows INI files."))
+ "Generic mode for MS-Windows INI files.
+You can use `ini-generic-mode-find-file-hook' to enter this mode
+automatically for INI files whose names do not end in \".ini\"."
+ :group 'generic-x)
+
+(defun ini-generic-mode-find-file-hook ()
+ "Hook function to enter Ini-Generic mode automatically for INI files.
+Done if the first few lines of a file in Fundamental mode look
+like an INI file. You can add this hook to `find-file-hook'."
+ (and (eq major-mode 'fundamental-mode)
+ (save-excursion
+ (goto-char (point-min))
+ (and (looking-at "^\\s-*\\[.*\\]")
+ (ini-generic-mode)))))
+(defalias 'generic-mode-ini-file-find-file-hook 'ini-generic-mode-find-file-hook))
;;; Windows REG files
;;; Unfortunately, Windows 95 and Windows NT have different REG file syntax!
(lambda ()
(setq imenu-generic-expression
'((nil "^\\s-*\\(.*\\)\\s-*=" 1))))))
- "Generic mode for MS-Windows Registry files."))
+ "Generic mode for MS-Windows Registry files."
+ :group 'generic-x))
;;; DOS/Windows BAT files
(when (memq 'bat-generic-mode generic-extras-enable-list)
"\\`[cC][oO][nN][fF][iI][gG]\\."
"\\`[aA][uU][tT][oO][eE][xX][eE][cC]\\.")
'(generic-bat-mode-setup-function)
- "Generic mode for MS-Windows BAT files.")
+ "Generic mode for MS-Windows BAT files."
+ :group 'generic-x)
(defvar bat-generic-mode-syntax-table nil
"Syntax table in use in bat-generic-mode buffers.")
(compile
(concat (w32-shell-name) " -c " (buffer-file-name)))))
+(eval-when-compile (require 'comint))
(defun bat-generic-mode-run-as-comint ()
"Run the current BAT file in a comint buffer."
(interactive)
(lambda ()
(setq imenu-generic-expression
'((nil "\\s-/\\([^/]+\\)/[i, \t\n]" 1))))))
- "Mode for Mailagent rules files."))
+ "Mode for Mailagent rules files."
+ :group 'generic-x))
;; Solaris/Sys V prototype files
(when (memq 'prototype-generic-mode generic-extras-enable-list)
(2 font-lock-variable-name-face)))
'("prototype\\'")
nil
- "Mode for Sys V prototype files."))
+ "Mode for Sys V prototype files."
+ :group 'generic-x))
;; Solaris/Sys V pkginfo files
(when (memq 'pkginfo-generic-mode generic-extras-enable-list)
(2 font-lock-variable-name-face)))
'("pkginfo\\'")
nil
- "Mode for Sys V pkginfo files."))
+ "Mode for Sys V pkginfo files."
+ :group 'generic-x))
;; Javascript mode
;; Includes extra keywords from Armando Singer [asinger@MAIL.COLGATE.EDU]
(setq imenu-generic-expression
'((nil "^function\\s-+\\([A-Za-z0-9_]+\\)" 1)
("*Variables*" "^var\\s-+\\([A-Za-z0-9_]+\\)" 1))))))
- "Mode for JavaScript files.")
+ "Mode for JavaScript files."
+ :group 'generic-x)
;; VRML files
(define-generic-mode vrml-generic-mode
("*Definitions*"
"DEF\\s-+\\([-A-Za-z0-9_]+\\)\\s-+\\([A-Za-z0-9]+\\)\\s-*{"
1))))))
- "Generic Mode for VRML files.")
+ "Generic Mode for VRML files."
+ :group 'generic-x)
;; Java Manifests
(define-generic-mode java-manifest-generic-mode
(2 font-lock-constant-face)))
'("[mM][aA][nN][iI][fF][eE][sS][tT]\\.[mM][fF]\\'")
nil
- "Mode for Java Manifest files")
+ "Mode for Java Manifest files"
+ :group 'generic-x)
;; Java properties files
(define-generic-mode java-properties-generic-mode
(lambda ()
(setq imenu-generic-expression
'((nil "^\\([^#! \t\n\r=:]+\\)" 1))))))
- "Mode for Java properties files.")
+ "Mode for Java properties files."
+ :group 'generic-x)
;; C shell alias definitions
(when (memq 'alias-generic-mode generic-extras-enable-list)
(lambda ()
(setq imenu-generic-expression
'((nil "^\\(alias\\|unalias\\)\\s-+\\([-a-zA-Z0-9_]+\\)" 2))))))
- "Mode for C Shell alias files."))
+ "Mode for C Shell alias files."
+ :group 'generic-x))
;;; Windows RC files
;; Contributed by ACorreir@pervasive-sw.com (Alfred Correira)
'("^#[ \t]*\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-constant-face)
(2 font-lock-variable-name-face nil t))))
- '("\\.[rR][cC]$")
+ '("\\.[rR][cC]\\'")
nil
- "Generic mode for MS-Windows Resource files."))
+ "Generic mode for MS-Windows Resource files."
+ :group 'generic-x))
;; InstallShield RUL files
;; Contributed by Alfred.Correira@Pervasive.Com
(generic-make-keywords-list
installshield-funarg-constants-list
font-lock-variable-name-face "[^_]" "[^_]"))) ; is this face the best choice?
- '("\\.[rR][uU][lL]$")
+ '("\\.[rR][uU][lL]\\'")
'(generic-rul-mode-setup-function)
- "Generic mode for InstallShield RUL files.")
+ "Generic mode for InstallShield RUL files."
+ :group 'generic-x)
(define-skeleton rul-if
"Insert an if statement."
(2 font-lock-variable-name-face)))
'("\\.mailrc\\'")
nil
- "Mode for mailrc files.")
+ "Mode for mailrc files."
+ :group 'generic-x)
;; Inetd.conf
(when (memq 'inetd-conf-generic-mode generic-extras-enable-list)
(function
(lambda ()
(setq imenu-generic-expression
- '((nil "^\\([-A-Za-z0-9_]+\\)" 1))))))))
+ '((nil "^\\([-A-Za-z0-9_]+\\)" 1))))))
+ :group 'generic-x))
;; Services
(when (memq 'etc-services-generic-mode generic-extras-enable-list)
(function
(lambda ()
(setq imenu-generic-expression
- '((nil "^\\([-A-Za-z0-9_]+\\)" 1))))))))
+ '((nil "^\\([-A-Za-z0-9_]+\\)" 1))))))
+ :group 'generic-x))
;; Password and Group files
(when (memq 'etc-passwd-generic-mode generic-extras-enable-list)
(function
(lambda ()
(setq imenu-generic-expression
- '((nil "^\\([-A-Za-z0-9_]+\\):" 1))))))))
+ '((nil "^\\([-A-Za-z0-9_]+\\):" 1))))))
+ :group 'generic-x))
;; Fstab
(when (memq 'etc-fstab-generic-mode generic-extras-enable-list)
"auto"
"ignore")
'(("^\\([/-A-Za-z0-9_]+\\)\\s-+\\([/-A-Za-z0-9_]+\\)"
- (1 font-lock-type-face)
- (2 font-lock-variable-name-face)))
+ (1 font-lock-type-face t)
+ (2 font-lock-variable-name-face t)))
'("/etc/[v]*fstab\\'")
(list
(function
(lambda ()
(setq imenu-generic-expression
- '((nil "^\\([/-A-Za-z0-9_]+\\)\\s-+" 1))))))))
+ '((nil "^\\([/-A-Za-z0-9_]+\\)\\s-+" 1))))))
+ :group 'generic-x))
;; From Jacques Duthen <jacques.duthen@sncf.fr>
(eval-when-compile
(defface show-tabs-tab-face
'((((class grayscale) (background light)) (:background "DimGray" :weight bold))
(((class grayscale) (background dark)) (:background "LightGray" :weight bold))
- (((class color) (background light)) (:background "red"))
- (((class color) (background dark)) (:background "red"))
+ (((class color) (min-colors 88)) (:background "red1"))
+ (((class color)) (:background "red"))
(t (:weight bold)))
"Font Lock mode face used to highlight TABs."
- :group 'show-tabs)
+ :group 'generic-x)
(defface show-tabs-space-face
'((((class grayscale) (background light)) (:background "DimGray" :weight bold))
(((class grayscale) (background dark)) (:background "LightGray" :weight bold))
- (((class color) (background light)) (:background "yellow"))
- (((class color) (background dark)) (:background "yellow"))
+ (((class color) (min-colors 88)) (:background "yellow1"))
+ (((class color)) (:background "yellow"))
(t (:weight bold)))
"Font Lock mode face used to highlight spaces."
- :group 'show-tabs)
+ :group 'generic-x)
(define-generic-mode show-tabs-generic-mode
nil ;; no comment char
nil ;; no auto-mode-alist
;; '(show-tabs-generic-mode-hook-fun)
nil
- "Generic mode to show tabs and trailing spaces")
+ "Generic mode to show tabs and trailing spaces"
+ :group 'generic-x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DNS modes
;; List of additional automode-alist expressions
'("/etc/named.boot\\'")
;; List of set up functions to call
- nil)
+ nil
+ :group 'generic-x)
(define-generic-mode named-database-generic-mode
;; List of comment characters
;; List of additional font-lock-expressions
'(("\\([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\\)" 1 font-lock-constant-face)
("^\\([.A-Za-z0-9]+\\)" 1 font-lock-variable-name-face))
- ;; List of additional automode-alist expressions
+ ;; List of additional auto-mode-alist expressions
nil
;; List of set up functions to call
- nil)
+ nil
+ :group 'generic-x)
(defvar named-database-time-string "%Y%m%d%H"
"Timestring for named serial numbers.")
'("nameserver" "domain" "search" "sortlist" "options")
;; List of additional font-lock-expressions
nil
- ;; List of additional automode-alist expressions
+ ;; List of additional auto-mode-alist expressions
'("/etc/resolv[e]?.conf\\'")
;; List of set up functions to call
- nil)
+ nil
+ :group 'generic-x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Modes for spice and common electrical engineering circuit netlist formats
(function
(lambda()
(setq font-lock-defaults '(generic-font-lock-keywords nil t)))))
- "Generic mode for SPICE circuit netlist files.")
+ "Generic mode for SPICE circuit netlist files."
+ :group 'generic-x)
(define-generic-mode ibis-generic-mode
'(?|)
("\\(\\(_\\|\\w\\)+\\)\\s-*=" 1 font-lock-variable-name-face))
'("\\.[iI][bB][sS]\\'")
'(generic-bracket-support)
- "Generic mode for IBIS circuit netlist files.")
+ "Generic mode for IBIS circuit netlist files."
+ :group 'generic-x)
(define-generic-mode astap-generic-mode
nil
(function
(lambda()
(setq font-lock-defaults '(generic-font-lock-keywords nil t)))))
- "Generic mode for ASTAP circuit netlist files.")
+ "Generic mode for ASTAP circuit netlist files."
+ :group 'generic-x)
(define-generic-mode etc-modules-conf-generic-mode
;; List of comment characters
;; List of additional automode-alist expressions
'("/etc/modules.conf" "/etc/conf.modules")
;; List of set up functions to call
- nil)
+ nil
+ :group 'generic-x)
(provide 'generic-x)