Mercurial > emacs
comparison lisp/generic-x.el @ 90143:146c086df160
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-37
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 241-257)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 59-65)
- Update from CVS
- Merge from emacs--cvs-trunk--0
- (mm-string-to-multibyte): Use Gnus trunk definition.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 14 Apr 2005 05:03:52 +0000 |
parents | 02f1dbc4a199 0428c421c463 |
children | 08185296b491 |
comparison
equal
deleted
inserted
replaced
90142:627771f44771 | 90143:146c086df160 |
---|---|
38 ;; affected by the variables `generic-define-mswindows-modes' and | 38 ;; affected by the variables `generic-define-mswindows-modes' and |
39 ;; `generic-define-unix-modes' (which see). | 39 ;; `generic-define-unix-modes' (which see). |
40 ;; | 40 ;; |
41 ;; You can also send in new modes; if the file types a reasonably common, | 41 ;; You can also send in new modes; if the file types a reasonably common, |
42 ;; we would like to install them. | 42 ;; we would like to install them. |
43 ;; | |
44 ;; DEFAULT GENERIC MODE: | |
45 ;; | |
46 ;; This file provides a hook which automatically puts a file into | |
47 ;; `default-generic-mode' if the first few lines of a file in | |
48 ;; fundamental mode start with a hash comment character. To disable | |
49 ;; this functionality, set the variable `generic-use-find-file-hook' | |
50 ;; to nil BEFORE loading generic-x. See the variables | |
51 ;; `generic-lines-to-scan' and `generic-find-file-regexp' for | |
52 ;; customization options. | |
43 ;; | 53 ;; |
44 ;; PROBLEMS WHEN USED WITH FOLDING MODE: | 54 ;; PROBLEMS WHEN USED WITH FOLDING MODE: |
45 ;; | 55 ;; |
46 ;; [The following relates to the obsolete selective-display technique. | 56 ;; [The following relates to the obsolete selective-display technique. |
47 ;; Folding mode should use invisible text properties instead. -- Dave | 57 ;; Folding mode should use invisible text properties instead. -- Dave |
93 ;;; Code: | 103 ;;; Code: |
94 | 104 |
95 (require 'font-lock) | 105 (require 'font-lock) |
96 | 106 |
97 (defgroup generic-x nil | 107 (defgroup generic-x nil |
98 "Extra modes for generic mode." | 108 "A collection of generic modes." |
99 :prefix "generic-" | 109 :prefix "generic-" |
100 :group 'generic | 110 :group 'data |
101 :version "20.3") | 111 :version "20.3") |
112 | |
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
114 ;; Default-Generic mode | |
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
116 | |
117 (defcustom generic-use-find-file-hook t | |
118 "*If non-nil, add a hook to enter `default-generic-mode' automatically. | |
119 This is done if the first few lines of a file in fundamental mode | |
120 start with a hash comment character." | |
121 :group 'generic-x | |
122 :type 'boolean) | |
123 | |
124 (defcustom generic-lines-to-scan 3 | |
125 "*Number of lines that `generic-mode-find-file-hook' looks at. | |
126 Relevant when deciding whether to enter Default-Generic mode automatically. | |
127 This variable should be set to a small positive number." | |
128 :group 'generic-x | |
129 :type 'integer) | |
130 | |
131 (defcustom generic-find-file-regexp "^#" | |
132 "*Regular expression used by `generic-mode-find-file-hook'. | |
133 Files in fundamental mode whose first few lines contain a match | |
134 for this regexp, should be put into Default-Generic mode instead. | |
135 The number of lines tested for the matches is specified by the | |
136 value of the variable `generic-lines-to-scan', which see." | |
137 :group 'generic-x | |
138 :type 'regexp) | |
139 | |
140 (defcustom generic-ignore-files-regexp "[Tt][Aa][Gg][Ss]\\'" | |
141 "*Regular expression used by `generic-mode-find-file-hook'. | |
142 Files whose names match this regular expression should not be put | |
143 into Default-Generic mode, even if they have lines which match | |
144 the regexp in `generic-find-file-regexp'. If the value is nil, | |
145 `generic-mode-find-file-hook' does not check the file names." | |
146 :group 'generic-x | |
147 :type '(choice (const :tag "Don't check file names" nil) regexp)) | |
148 | |
149 ;; This generic mode is always defined | |
150 (define-generic-mode default-generic-mode (list ?#) nil nil nil nil :group 'generic) | |
151 | |
152 ;; A more general solution would allow us to enter generic-mode for | |
153 ;; *any* comment character, but would require us to synthesize a new | |
154 ;; generic-mode on the fly. I think this gives us most of what we | |
155 ;; want. | |
156 (defun generic-mode-find-file-hook () | |
157 "Hook function to enter Default-Generic mode automatically. | |
158 | |
159 Done if the first few lines of a file in Fundamental mode start | |
160 with a match for the regexp in `generic-find-file-regexp', unless | |
161 the file's name matches the regexp which is the value of the | |
162 variable `generic-ignore-files-regexp'. | |
163 | |
164 This hook will be installed if the variable | |
165 `generic-use-find-file-hook' is non-nil. The variable | |
166 `generic-lines-to-scan' determines the number of lines to look at." | |
167 (when (and (eq major-mode 'fundamental-mode) | |
168 (or (null generic-ignore-files-regexp) | |
169 (not (string-match | |
170 generic-ignore-files-regexp | |
171 (file-name-sans-versions buffer-file-name))))) | |
172 (save-excursion | |
173 (goto-char (point-min)) | |
174 (when (re-search-forward generic-find-file-regexp | |
175 (save-excursion | |
176 (forward-line generic-lines-to-scan) | |
177 (point)) t) | |
178 (goto-char (point-min)) | |
179 (default-generic-mode))))) | |
180 | |
181 (and generic-use-find-file-hook | |
182 (add-hook 'find-file-hook 'generic-mode-find-file-hook)) | |
183 | |
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
185 ;; Other Generic modes | |
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
102 | 187 |
103 (defcustom generic-extras-enable-list nil | 188 (defcustom generic-extras-enable-list nil |
104 "*List of generic modes to enable by default. | 189 "*List of generic modes to enable by default. |
105 Each entry in the list should be a symbol. The variables | 190 Each entry in the list should be a symbol. The variables |
106 `generic-define-mswindows-modes' and `generic-define-unix-modes' | 191 `generic-define-mswindows-modes' and `generic-define-unix-modes' |
147 inetd-conf-generic-mode | 232 inetd-conf-generic-mode |
148 etc-services-generic-mode | 233 etc-services-generic-mode |
149 etc-passwd-generic-mode | 234 etc-passwd-generic-mode |
150 etc-fstab-generic-mode) | 235 etc-fstab-generic-mode) |
151 generic-extras-enable-list))) | 236 generic-extras-enable-list))) |
152 | |
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
154 ;; Generic-modes | |
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
156 | 237 |
157 ;;; Apache | 238 ;;; Apache |
158 (when (memq 'apache-conf-generic-mode generic-extras-enable-list) | 239 (when (memq 'apache-conf-generic-mode generic-extras-enable-list) |
159 | 240 |
160 (define-generic-mode apache-conf-generic-mode | 241 (define-generic-mode apache-conf-generic-mode |
282 (function | 363 (function |
283 (lambda () | 364 (lambda () |
284 (setq imenu-generic-expression | 365 (setq imenu-generic-expression |
285 '((nil "^\\[\\(.*\\)\\]" 1) | 366 '((nil "^\\[\\(.*\\)\\]" 1) |
286 ("*Variables*" "^\\s-*\\([^=]+\\)\\s-*=" 1)))))) | 367 ("*Variables*" "^\\s-*\\([^=]+\\)\\s-*=" 1)))))) |
287 "Generic mode for MS-Windows INI files." | 368 "Generic mode for MS-Windows INI files. |
288 :group 'generic-x)) | 369 You can use `ini-generic-mode-find-file-hook' to enter this mode |
370 automatically for INI files whose names do not end in \".ini\"." | |
371 :group 'generic-x) | |
372 | |
373 (defun ini-generic-mode-find-file-hook () | |
374 "Hook function to enter Ini-Generic mode automatically for INI files. | |
375 Done if the first few lines of a file in Fundamental mode look | |
376 like an INI file. You can add this hook to `find-file-hook'." | |
377 (and (eq major-mode 'fundamental-mode) | |
378 (save-excursion | |
379 (goto-char (point-min)) | |
380 (and (looking-at "^\\s-*\\[.*\\]") | |
381 (ini-generic-mode))))) | |
382 (defalias 'generic-mode-ini-file-find-file-hook 'ini-generic-mode-find-file-hook)) | |
289 | 383 |
290 ;;; Windows REG files | 384 ;;; Windows REG files |
291 ;;; Unfortunately, Windows 95 and Windows NT have different REG file syntax! | 385 ;;; Unfortunately, Windows 95 and Windows NT have different REG file syntax! |
292 (when (memq 'reg-generic-mode generic-extras-enable-list) | 386 (when (memq 'reg-generic-mode generic-extras-enable-list) |
293 | 387 |
394 (lambda(ign) | 488 (lambda(ign) |
395 (concat "*" (buffer-file-name) "*"))))) | 489 (concat "*" (buffer-file-name) "*"))))) |
396 (compile | 490 (compile |
397 (concat (w32-shell-name) " -c " (buffer-file-name))))) | 491 (concat (w32-shell-name) " -c " (buffer-file-name))))) |
398 | 492 |
493 (eval-when-compile (require 'comint)) | |
399 (defun bat-generic-mode-run-as-comint () | 494 (defun bat-generic-mode-run-as-comint () |
400 "Run the current BAT file in a comint buffer." | 495 "Run the current BAT file in a comint buffer." |
401 (interactive) | 496 (interactive) |
402 (require 'comint) | 497 (require 'comint) |
403 (let* ((file (buffer-file-name)) | 498 (let* ((file (buffer-file-name)) |
783 (1 font-lock-constant-face) | 878 (1 font-lock-constant-face) |
784 (2 font-lock-variable-name-face nil t))) | 879 (2 font-lock-variable-name-face nil t))) |
785 '("^#[ \t]*\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?" | 880 '("^#[ \t]*\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?" |
786 (1 font-lock-constant-face) | 881 (1 font-lock-constant-face) |
787 (2 font-lock-variable-name-face nil t)))) | 882 (2 font-lock-variable-name-face nil t)))) |
788 '("\\.[rR][cC]$") | 883 '("\\.[rR][cC]\\'") |
789 nil | 884 nil |
790 "Generic mode for MS-Windows Resource files." | 885 "Generic mode for MS-Windows Resource files." |
791 :group 'generic-x)) | 886 :group 'generic-x)) |
792 | 887 |
793 ;; InstallShield RUL files | 888 ;; InstallShield RUL files |
1404 font-lock-type-face "[^_]" "[^_]") | 1499 font-lock-type-face "[^_]" "[^_]") |
1405 ;; function argument constants | 1500 ;; function argument constants |
1406 (generic-make-keywords-list | 1501 (generic-make-keywords-list |
1407 installshield-funarg-constants-list | 1502 installshield-funarg-constants-list |
1408 font-lock-variable-name-face "[^_]" "[^_]"))) ; is this face the best choice? | 1503 font-lock-variable-name-face "[^_]" "[^_]"))) ; is this face the best choice? |
1409 '("\\.[rR][uU][lL]$") | 1504 '("\\.[rR][uU][lL]\\'") |
1410 '(generic-rul-mode-setup-function) | 1505 '(generic-rul-mode-setup-function) |
1411 "Generic mode for InstallShield RUL files." | 1506 "Generic mode for InstallShield RUL files." |
1412 :group 'generic-x) | 1507 :group 'generic-x) |
1413 | 1508 |
1414 (define-skeleton rul-if | 1509 (define-skeleton rul-if |
1582 "xfs" | 1677 "xfs" |
1583 "swap" | 1678 "swap" |
1584 "auto" | 1679 "auto" |
1585 "ignore") | 1680 "ignore") |
1586 '(("^\\([/-A-Za-z0-9_]+\\)\\s-+\\([/-A-Za-z0-9_]+\\)" | 1681 '(("^\\([/-A-Za-z0-9_]+\\)\\s-+\\([/-A-Za-z0-9_]+\\)" |
1587 (1 font-lock-type-face) | 1682 (1 font-lock-type-face t) |
1588 (2 font-lock-variable-name-face))) | 1683 (2 font-lock-variable-name-face t))) |
1589 '("/etc/[v]*fstab\\'") | 1684 '("/etc/[v]*fstab\\'") |
1590 (list | 1685 (list |
1591 (function | 1686 (function |
1592 (lambda () | 1687 (lambda () |
1593 (setq imenu-generic-expression | 1688 (setq imenu-generic-expression |
1665 ;; List of keywords | 1760 ;; List of keywords |
1666 '("IN" "NS" "CNAME" "SOA" "PTR" "MX" "A") | 1761 '("IN" "NS" "CNAME" "SOA" "PTR" "MX" "A") |
1667 ;; List of additional font-lock-expressions | 1762 ;; List of additional font-lock-expressions |
1668 '(("\\([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\\)" 1 font-lock-constant-face) | 1763 '(("\\([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\\)" 1 font-lock-constant-face) |
1669 ("^\\([.A-Za-z0-9]+\\)" 1 font-lock-variable-name-face)) | 1764 ("^\\([.A-Za-z0-9]+\\)" 1 font-lock-variable-name-face)) |
1670 ;; List of additional automode-alist expressions | 1765 ;; List of additional auto-mode-alist expressions |
1671 nil | 1766 nil |
1672 ;; List of set up functions to call | 1767 ;; List of set up functions to call |
1673 nil | 1768 nil |
1674 :group 'generic-x) | 1769 :group 'generic-x) |
1675 | 1770 |
1686 '(?#) | 1781 '(?#) |
1687 ;; List of keywords | 1782 ;; List of keywords |
1688 '("nameserver" "domain" "search" "sortlist" "options") | 1783 '("nameserver" "domain" "search" "sortlist" "options") |
1689 ;; List of additional font-lock-expressions | 1784 ;; List of additional font-lock-expressions |
1690 nil | 1785 nil |
1691 ;; List of additional automode-alist expressions | 1786 ;; List of additional auto-mode-alist expressions |
1692 '("/etc/resolv[e]?.conf\\'") | 1787 '("/etc/resolv[e]?.conf\\'") |
1693 ;; List of set up functions to call | 1788 ;; List of set up functions to call |
1694 nil | 1789 nil |
1695 :group 'generic-x) | 1790 :group 'generic-x) |
1696 | 1791 |