aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-03-06 18:45:39 +0000
committerRichard M. Stallman1998-03-06 18:45:39 +0000
commit728f84dcd840815683099a720a7283194f6534eb (patch)
tree6e7e2146321810777b9394cc4b720b93e907eb2f
parent1720e5081cc4aa388bd3d639867b217a4d139239 (diff)
downloademacs-728f84dcd840815683099a720a7283194f6534eb.tar.gz
emacs-728f84dcd840815683099a720a7283194f6534eb.zip
(generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
(generic-use-find-file-hook): Changed from defvar to defcustom. (generic-lines-to-scan): Changed from defvar to defcustom. (generic-find-file-regexp): Changed from defvar to defcustom.
-rw-r--r--lisp/generic.el103
1 files changed, 57 insertions, 46 deletions
diff --git a/lisp/generic.el b/lisp/generic.el
index 0214e5a56d2..4a9a6bac124 100644
--- a/lisp/generic.el
+++ b/lisp/generic.el
@@ -116,7 +116,7 @@
116;;; Code: 116;;; Code:
117 117
118;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 118;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119;; Variables 119;; Internal Variables
120;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 120;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 121
122(make-variable-buffer-local 122(make-variable-buffer-local
@@ -158,20 +158,33 @@ Each entry in the list looks like this:
158Do not add entries to this list directly; use `define-generic-mode' 158Do not add entries to this list directly; use `define-generic-mode'
159instead (which see).") 159instead (which see).")
160 160
161(defvar generic-use-find-file-hook t 161;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
162;; Customization Variables
163;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164
165(defcustom generic-use-find-file-hook t
162 "*If non-nil, add a hook to enter default-generic-mode automatically 166 "*If non-nil, add a hook to enter default-generic-mode automatically
163if the first few lines of a file in fundamental mode start with a hash 167if the first few lines of a file in fundamental mode start with a hash
164comment character.") 168comment character."
169 :group 'generic
170 :type 'boolean
171 )
165 172
166(defvar generic-lines-to-scan 3 173(defcustom generic-lines-to-scan 3
167 "*Number of lines that `generic-mode-find-file-hook' looks at 174 "*Number of lines that `generic-mode-find-file-hook' looks at
168when deciding whether to enter generic-mode automatically. 175when deciding whether to enter generic-mode automatically.
169This variable should be set to a small positive number.") 176This variable should be set to a small positive number."
177 :group 'generic
178 :type 'integer
179 )
170 180
171(defvar generic-find-file-regexp "#.*\n\\(.*\n\\)?" 181(defcustom generic-find-file-regexp "#.*\n\\(.*\n\\)?"
172 "*Regular expression used by `generic-mode-find-file-hook' 182 "*Regular expression used by `generic-mode-find-file-hook'
173to determine if files in fundamental mode should be put into 183to determine if files in fundamental mode should be put into
174`default-generic-mode' instead.") 184`default-generic-mode' instead."
185 :group 'generic
186 :type 'regexp
187 )
175 188
176;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 189;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177;; Inline functions 190;; Inline functions
@@ -189,7 +202,7 @@ to determine if files in fundamental mode should be put into
189(defsubst generic-mode-sanity-check (name comment-list keyword-list 202(defsubst generic-mode-sanity-check (name comment-list keyword-list
190 font-lock-list auto-mode-list 203 font-lock-list auto-mode-list
191 function-list &optional description) 204 function-list &optional description)
192 (if (not (symbolp name)) 205 (and (not (symbolp name))
193 (error "%s is not a symbol" (princ name))) 206 (error "%s is not a symbol" (princ name)))
194 207
195 (mapcar '(lambda (elt) 208 (mapcar '(lambda (elt)
@@ -198,7 +211,7 @@ to determine if files in fundamental mode should be put into
198 (list comment-list keyword-list font-lock-list 211 (list comment-list keyword-list font-lock-list
199 auto-mode-list function-list)) 212 auto-mode-list function-list))
200 213
201 (if (not (or (null description) (stringp description))) 214 (and (not (or (null description) (stringp description)))
202 (error "Description must be a string or nil")) 215 (error "Description must be a string or nil"))
203) 216)
204 217
@@ -273,12 +286,12 @@ non-nil, prepends entries to auto-mode-alist; otherwise, appends them."
273 (error "%s is not a list" (princ auto-mode-list))) 286 (error "%s is not a list" (princ auto-mode-list)))
274 287
275 (let ((new-mode (intern (symbol-name mode)))) 288 (let ((new-mode (intern (symbol-name mode))))
276 (if remove-old 289 (and remove-old
277 (let ((auto-mode-entry)) 290 (let ((auto-mode-entry))
278 (while (setq auto-mode-entry (rassq new-mode auto-mode-alist)) 291 (while (setq auto-mode-entry (rassq new-mode auto-mode-alist))
279 (setq auto-mode-alist 292 (setq auto-mode-alist
280 (delq auto-mode-entry 293 (delq auto-mode-entry
281 auto-mode-alist))))) 294 auto-mode-alist)))))
282 295
283 (mapcar '(lambda (entry) 296 (mapcar '(lambda (entry)
284 (generic-add-auto-mode-entry new-mode entry prepend)) 297 (generic-add-auto-mode-entry new-mode entry prepend))
@@ -310,9 +323,9 @@ If DESCRIPTION is provided, it is used as the docstring."
310 (generic-mode-list (assoc type generic-mode-alist)) 323 (generic-mode-list (assoc type generic-mode-alist))
311 ) 324 )
312 325
313 (if (not generic-mode-list) 326 (and (not generic-mode-list)
314 (error "Can't find generic-mode information for type %s" 327 (error "Can't find generic-mode information for type %s"
315 (princ generic-mode-name))) 328 (princ generic-mode-name)))
316 329
317 ;; Put this after the point where we read generic-mode-name! 330 ;; Put this after the point where we read generic-mode-name!
318 (kill-all-local-variables) 331 (kill-all-local-variables)
@@ -339,8 +352,8 @@ If DESCRIPTION is provided, it is used as the docstring."
339 (setq font-lock-defaults (list 'generic-font-lock-defaults nil)) 352 (setq font-lock-defaults (list 'generic-font-lock-defaults nil))
340 353
341 ;; Call a list of functions 354 ;; Call a list of functions
342 (if generic-mode-function-list 355 (and generic-mode-function-list
343 (mapcar 'funcall generic-mode-function-list)) 356 (mapcar 'funcall generic-mode-function-list))
344 ) 357 )
345 ) 358 )
346 359
@@ -382,8 +395,8 @@ Some generic modes are defined in `generic-x.el'."
382 comment)) 395 comment))
383 ) 396 )
384 (generic-mode-set-comment-char comment))) 397 (generic-mode-set-comment-char comment)))
385 (if (consp comment) 398 (and (consp comment)
386 (generic-mode-set-comment-pair comment))) 399 (generic-mode-set-comment-pair comment)))
387 400
388(defun generic-mode-set-comment-char (comment-char) 401(defun generic-mode-set-comment-char (comment-char)
389 "Set the given character as a comment character for generic mode." 402 "Set the given character as a comment character for generic mode."
@@ -439,11 +452,11 @@ Some generic modes are defined in `generic-x.el'."
439 ) 452 )
440 453
441 ;; Sanity checks 454 ;; Sanity checks
442 (if (not (and (stringp generic-comment-start) 455 (and (not (and (stringp generic-comment-start)
443 (stringp generic-comment-end))) 456 (stringp generic-comment-end)))
444 (error "Elements of cons pair must be strings")) 457 (error "Elements of cons pair must be strings"))
445 (if (not (and (equal (length generic-comment-start) 2) 458 (and (not (and (equal (length generic-comment-start) 2)
446 (equal (length generic-comment-end) 2))) 459 (equal (length generic-comment-end) 2)))
447 (error "Start and end must be exactly two characters long")) 460 (error "Start and end must be exactly two characters long"))
448 461
449 (let ((first (elt generic-comment-start 0)) 462 (let ((first (elt generic-comment-start 0))
@@ -482,7 +495,7 @@ Some generic modes are defined in `generic-x.el'."
482 "Set up font-lock functionality for generic mode." 495 "Set up font-lock functionality for generic mode."
483 (let ((generic-font-lock-expressions)) 496 (let ((generic-font-lock-expressions))
484 ;; Keywords 497 ;; Keywords
485 (if keywords 498 (and keywords
486 (setq 499 (setq
487 generic-font-lock-expressions 500 generic-font-lock-expressions
488 (append 501 (append
@@ -495,14 +508,13 @@ Some generic modes are defined in `generic-x.el'."
495 1 'font-lock-keyword-face)) 508 1 'font-lock-keyword-face))
496 generic-font-lock-expressions))) 509 generic-font-lock-expressions)))
497 ;; Other font-lock expressions 510 ;; Other font-lock expressions
498 (if font-lock-expressions 511 (and font-lock-expressions
499 (setq generic-font-lock-expressions 512 (setq generic-font-lock-expressions
500 (append 513 (append
501 font-lock-expressions 514 font-lock-expressions
502 generic-font-lock-expressions))) 515 generic-font-lock-expressions)))
503 (if (not (or font-lock-expressions keywords)) 516 (and (or font-lock-expressions keywords)
504 nil 517 (setq generic-font-lock-defaults generic-font-lock-expressions))
505 (setq generic-font-lock-defaults generic-font-lock-expressions))
506 )) 518 ))
507 519
508;; Support for [KEYWORD] constructs found in INF, INI and Samba files 520;; Support for [KEYWORD] constructs found in INF, INI and Samba files
@@ -526,10 +538,10 @@ comment character. This hook will be installed if the variable
526determines the number of lines to look at." 538determines the number of lines to look at."
527 (if (not (eq major-mode 'fundamental-mode)) 539 (if (not (eq major-mode 'fundamental-mode))
528 nil 540 nil
529 (if (or (> 1 generic-lines-to-scan) 541 (and (or (> 1 generic-lines-to-scan)
530 (< 50 generic-lines-to-scan)) 542 (< 50 generic-lines-to-scan))
531 (error "Variable `generic-lines-to-scan' should be set to a small" 543 (error "Variable `generic-lines-to-scan' should be set to a small"
532 " positive number")) 544 " positive number"))
533 (let ((comment-regexp "") 545 (let ((comment-regexp "")
534 (count 0) 546 (count 0)
535 ) 547 )
@@ -539,19 +551,18 @@ determines the number of lines to look at."
539 (setq count (1+ count))) 551 (setq count (1+ count)))
540 (save-excursion 552 (save-excursion
541 (goto-char (point-min)) 553 (goto-char (point-min))
542 (if (looking-at comment-regexp) 554 (and (looking-at comment-regexp)
543 (generic-mode-with-type 'default-generic-mode)))))) 555 (generic-mode-with-type 'default-generic-mode))))))
544 556
545(defun generic-mode-ini-file-find-file-hook () 557(defun generic-mode-ini-file-find-file-hook ()
546 "Hook to enter default-generic-mode automatically 558 "Hook to enter default-generic-mode automatically
547if the first few lines of a file in fundamental-mode look like an INI file. 559if the first few lines of a file in fundamental-mode look like an INI file.
548This hook is NOT installed by default." 560This hook is NOT installed by default."
549 (if (not (eq major-mode 'fundamental-mode)) 561 (and (eq major-mode 'fundamental-mode)
550 nil 562 (save-excursion
551 (save-excursion 563 (goto-char (point-min))
552 (goto-char (point-min)) 564 (and (looking-at "^\\s-*\\[.*\\]")
553 (if (looking-at "^\\s-*\\[.*\\]") 565 (generic-mode-with-type 'ini-generic-mode)))))
554 (generic-mode-with-type 'ini-generic-mode)))))
555 566
556(and generic-use-find-file-hook 567(and generic-use-find-file-hook
557 (add-hook 'find-file-hooks 'generic-mode-find-file-hook)) 568 (add-hook 'find-file-hooks 'generic-mode-find-file-hook))
@@ -563,8 +574,8 @@ The regexp is highlighted with FACE."
563 ;; Don't check here; face may not be defined yet 574 ;; Don't check here; face may not be defined yet
564 ;; (if (not (facep face)) 575 ;; (if (not (facep face))
565 ;; (error "Face %s is not defined" (princ face))) 576 ;; (error "Face %s is not defined" (princ face)))
566 (if (not (listp keywords-list)) 577 (and (not (listp keywords-list))
567 (error "Keywords argument must be a list of strings")) 578 (error "Keywords argument must be a list of strings"))
568 (list 579 (list
569 (concat 580 (concat
570 (or prefix "") 581 (or prefix "")