/[emacs]/emacs/lisp/generic-x.el
ViewVC logotype

Diff of /emacs/lisp/generic-x.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.30 by dann, Fri Apr 8 14:26:13 2005 UTC revision 1.31 by lute, Mon Apr 11 08:08:02 2005 UTC
# Line 41  Line 41 
41  ;; You can also send in new modes; if the file types a reasonably common,  ;; You can also send in new modes; if the file types a reasonably common,
42  ;; we would like to install them.  ;; 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.
53    ;;
54  ;; PROBLEMS WHEN USED WITH FOLDING MODE:  ;; PROBLEMS WHEN USED WITH FOLDING MODE:
55  ;;  ;;
56  ;; [The following relates to the obsolete selective-display technique.  ;; [The following relates to the obsolete selective-display technique.
# Line 95  Line 105 
105  (require 'font-lock)  (require 'font-lock)
106    
107  (defgroup generic-x nil  (defgroup generic-x nil
108    "Extra modes for generic mode."    "A collection of generic modes."
109    :prefix "generic-"    :prefix "generic-"
110    :group 'generic    :group 'data
111    :version "20.3")    :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    (defun generic-mode-ini-file-find-file-hook ()
182      "Hook function to enter Default-Generic mode automatically for INI files.
183    Done if the first few lines of a file in Fundamental mode look like an
184    INI file.  This hook is NOT installed by default."
185      (and (eq major-mode 'fundamental-mode)
186           (save-excursion
187             (goto-char (point-min))
188             (and (looking-at "^\\s-*\\[.*\\]")
189                  (ini-generic-mode)))))
190    
191    (and generic-use-find-file-hook
192        (add-hook 'find-file-hook 'generic-mode-find-file-hook))
193    
194    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195    ;; Other Generic modes
196    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197    
198  (defcustom generic-extras-enable-list nil  (defcustom generic-extras-enable-list nil
199    "*List of generic modes to enable by default.    "*List of generic modes to enable by default.
200  Each entry in the list should be a symbol.  The variables  Each entry in the list should be a symbol.  The variables
# Line 150  generic-x to enable the specified modes. Line 245  generic-x to enable the specified modes.
245                       etc-fstab-generic-mode)                       etc-fstab-generic-mode)
246                     generic-extras-enable-list)))                     generic-extras-enable-list)))
247    
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
 ;; Generic-modes  
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
   
248  ;;; Apache  ;;; Apache
249  (when (memq 'apache-conf-generic-mode generic-extras-enable-list)  (when (memq 'apache-conf-generic-mode generic-extras-enable-list)
250    

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26