44
44
" Align assignments to this column by default with \\ [conf-align-assignments].
45
45
If this number is negative, the `=' comes before the whitespace. Use 0 to
46
46
not align (only setting space according to `conf-assignment-space' )."
47
- :type 'integer
48
- :group 'conf )
47
+ :type 'integer )
49
48
50
49
(defcustom conf-javaprop-assignment-column 32
51
50
" Value for `conf-assignment-column' in Java properties buffers."
52
- :type 'integer
53
- :group 'conf )
51
+ :type 'integer )
54
52
55
53
(defcustom conf-colon-assignment-column (- (abs conf-assignment-column))
56
54
" Value for `conf-assignment-column' in Java properties buffers."
57
- :type 'integer
58
- :group 'conf )
55
+ :type 'integer )
59
56
60
57
(defcustom conf-assignment-space t
61
58
" Put at least one space around assignments when aligning."
62
- :type 'boolean
63
- :group 'conf )
59
+ :type 'boolean )
64
60
65
61
(defcustom conf-colon-assignment-space nil
66
62
" Value for `conf-assignment-space' in colon style Conf mode buffers."
67
- :type 'boolean
68
- :group 'conf )
63
+ :type 'boolean )
69
64
70
65
(defvar conf-mode-map
71
66
(let ((map (make-sparse-keymap ))
@@ -349,9 +344,37 @@ unbalanced, but hey...)"
349
344
(scan-error depth))))
350
345
351
346
347
+ (defun conf--guess-mode ()
348
+ " Try to guess sub-mode of `conf-mode' based on buffer content."
349
+ (let ((unix 0 ) (win 0 ) (equal 0 ) (colon 0 ) (space 0 ) (jp 0 ))
350
+ (save-excursion
351
+ (goto-char (point-min ))
352
+ (while (not (eobp ))
353
+ (skip-chars-forward " \t\f " )
354
+ (cond ((eq (char-after ) ?\# ) (setq unix (1+ unix)))
355
+ ((eq (char-after ) ?\; ) (setq win (1+ win)))
356
+ ((eq (char-after ) ?\[ )) ; nop
357
+ ((eolp )) ; nop
358
+ ((eq (char-after ) ?} )) ; nop
359
+ ; ; recognize at most double spaces within names
360
+ ((looking-at " [^ \t\n =:]+\\ (?: ?[^ \t\n =:]+\\ )*[ \t ]*[=:]" )
361
+ (if (eq (char-before (match-end 0 )) ?= )
362
+ (setq equal (1+ equal))
363
+ (setq colon (1+ colon))))
364
+ ((looking-at " /[/*]" ) (setq jp (1+ jp)))
365
+ ((looking-at " .*{" )) ; nop
366
+ ((setq space (1+ space))))
367
+ (forward-line )))
368
+ (cond
369
+ ((> jp (max unix win 3 )) #'conf-javaprop-mode )
370
+ ((> colon (max equal space)) #'conf-colon-mode )
371
+ ((> space (max equal colon)) #'conf-space-mode )
372
+ ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt )))
373
+ #'conf-windows-mode )
374
+ (t #'conf-unix-mode ))))
352
375
353
376
;;;### autoload
354
- (defun conf-mode ()
377
+ (define-derived-mode conf-mode nil " Conf[?] "
355
378
" Mode for Unix and Windows Conf files and Java properties.
356
379
Most conf files know only three kinds of constructs: parameter
357
380
assignments optionally grouped into sections and comments. Yet
@@ -382,75 +405,37 @@ See also `conf-space-mode', `conf-colon-mode', `conf-javaprop-mode',
382
405
383
406
\\ {conf-mode-map}"
384
407
385
- (interactive )
386
408
; ; `conf-mode' plays two roles: it's the parent of several sub-modes
387
409
; ; but it's also the function that chooses between those submodes.
388
410
; ; To tell the difference between those two cases where the function
389
411
; ; might be called, we check `delay-mode-hooks' .
390
412
; ; (adopted from tex-mode.el)
391
413
(if (not delay-mode-hooks)
392
- ; ; try to guess sub-mode of conf-mode based on buffer content
393
- (let ((unix 0 ) (win 0 ) (equal 0 ) (colon 0 ) (space 0 ) (jp 0 ))
394
- (save-excursion
395
- (goto-char (point-min ))
396
- (while (not (eobp ))
397
- (skip-chars-forward " \t\f " )
398
- (cond ((eq (char-after ) ?\# ) (setq unix (1+ unix)))
399
- ((eq (char-after ) ?\; ) (setq win (1+ win)))
400
- ((eq (char-after ) ?\[ )) ; nop
401
- ((eolp )) ; nop
402
- ((eq (char-after ) ?} )) ; nop
403
- ; ; recognize at most double spaces within names
404
- ((looking-at " [^ \t\n =:]+\\ (?: ?[^ \t\n =:]+\\ )*[ \t ]*[=:]" )
405
- (if (eq (char-before (match-end 0 )) ?= )
406
- (setq equal (1+ equal))
407
- (setq colon (1+ colon))))
408
- ((looking-at " /[/*]" ) (setq jp (1+ jp)))
409
- ((looking-at " .*{" )) ; nop
410
- ((setq space (1+ space))))
411
- (forward-line )))
412
- (cond
413
- ((> jp (max unix win 3 )) (conf-javaprop-mode ))
414
- ((> colon (max equal space)) (conf-colon-mode ))
415
- ((> space (max equal colon)) (conf-space-mode ))
416
- ((or (> win unix) (and (= win unix) (eq system-type 'windows-nt )))
417
- (conf-windows-mode ))
418
- (t (conf-unix-mode ))))
419
-
420
- (kill-all-local-variables )
421
- (use-local-map conf-mode-map)
422
- (setq major-mode 'conf-mode
423
- mode-name " Conf[?]" )
424
- (set (make-local-variable 'font-lock-defaults )
425
- '(conf-font-lock-keywords nil t nil nil ))
414
+ (funcall (conf--guess-mode))
415
+
416
+ (setq-local font-lock-defaults '(conf-font-lock-keywords nil t nil nil ))
426
417
; ; Let newcomment.el decide this for itself.
427
- ; ; (set (make-local-variable 'comment-use-syntax) t)
428
- (set (make-local-variable 'parse-sexp-ignore-comments ) t )
429
- (set (make-local-variable 'outline-regexp )
430
- " [ \t ]*\\ (?:\\ [\\ |.+[ \t\n ]*{\\ )" )
431
- (set (make-local-variable 'outline-heading-end-regexp )
432
- " [\n }]" )
433
- (set (make-local-variable 'outline-level )
434
- 'conf-outline-level )
435
- (set-syntax-table conf-mode-syntax-table)
436
- (setq imenu-generic-expression
437
- '((" Parameters" " ^[ \t ]*\\ (.+?\\ )[ \t ]*=" 1 )
438
- ; ; [section]
439
- (nil " ^[ \t ]*\\ [[ \t ]*\\ (.+\\ )[ \t ]*\\ ]" 1 )
440
- ; ; section { ... }
441
- (nil " ^[ \t ]*\\ ([^=:{} \t\n ][^=:{}\n ]+\\ )[ \t\n ]*{" 1 )))
442
- (run-mode-hooks 'conf-mode-hook )))
418
+ ; ; (setq-local comment-use-syntax t)
419
+ (setq-local parse-sexp-ignore-comments t )
420
+ (setq-local outline-regexp " [ \t ]*\\ (?:\\ [\\ |.+[ \t\n ]*{\\ )" )
421
+ (setq-local outline-heading-end-regexp " [\n }]" )
422
+ (setq-local outline-level #'conf-outline-level )
423
+ (setq-local imenu-generic-expression
424
+ '((" Parameters" " ^[ \t ]*\\ (.+?\\ )[ \t ]*=" 1 )
425
+ ; ; [section]
426
+ (nil " ^[ \t ]*\\ [[ \t ]*\\ (.+\\ )[ \t ]*\\ ]" 1 )
427
+ ; ; section { ... }
428
+ (nil " ^[ \t ]*\\ ([^=:{} \t\n ][^=:{}\n ]+\\ )[ \t\n ]*{" 1 )))))
443
429
444
430
(defun conf-mode-initialize (comment &optional font-lock )
445
431
" Initializations for sub-modes of `conf-mode' .
446
432
COMMENT initializes `comment-start' and `comment-start-skip' .
447
433
The optional arg FONT-LOCK is the value for FONT-LOCK-KEYWORDS."
448
- (set ( make -local-variable ' comment-start) comment)
449
- (set ( make -local-variable ' comment-start-skip)
450
- (concat (regexp-quote comment-start) " +\\ s *" ))
434
+ (setq -local comment-start comment)
435
+ (setq -local comment-start-skip
436
+ (concat (regexp-quote comment-start) " +\\ s *" ))
451
437
(if font-lock
452
- (set (make-local-variable 'font-lock-defaults )
453
- `(, font-lock nil t nil nil ))))
438
+ (setq-local font-lock-defaults `(, font-lock nil t nil nil ))))
454
439
455
440
;;;### autoload
456
441
(define-derived-mode conf-unix-mode conf-mode " Conf[Unix]"
@@ -497,13 +482,11 @@ x.1 =
497
482
x.2.y.1.z.1 =
498
483
x.2.y.1.z.2.zz ="
499
484
(conf-mode-initialize " #" 'conf-javaprop-font-lock-keywords )
500
- (set (make-local-variable 'conf-assignment-column )
501
- conf-javaprop-assignment-column)
502
- (set (make-local-variable 'conf-assignment-regexp )
503
- " .+?\\ ([ \t ]*[=: \t ][ \t ]*\\ |$\\ )" )
504
- (setq comment-start-skip " \\ (?:#+\\ |/[/*]+\\ )\\ s *" )
505
- (setq imenu-generic-expression
506
- '((" Parameters" " ^[ \t ]*\\ (.+?\\ )[=: \t ]" 1 ))))
485
+ (setq-local conf-assignment-column conf-javaprop-assignment-column)
486
+ (setq-local conf-assignment-regexp " .+?\\ ([ \t ]*[=: \t ][ \t ]*\\ |$\\ )" )
487
+ (setq-local comment-start-skip " \\ (?:#+\\ |/[/*]+\\ )\\ s *" )
488
+ (setq-local imenu-generic-expression
489
+ '((" Parameters" " ^[ \t ]*\\ (.+?\\ )[=: \t ]" 1 ))))
507
490
508
491
;;;### autoload
509
492
(define-derived-mode conf-space-mode conf-unix-mode " Conf[Space]"
@@ -529,20 +512,18 @@ class desktop
529
512
add /dev/audio desktop
530
513
add /dev/mixer desktop"
531
514
(conf-mode-initialize " #" 'conf-space-font-lock-keywords )
532
- (make-local-variable 'conf-assignment-sign )
533
- (setq conf-assignment-sign nil )
534
- (make-local-variable 'conf-space-keywords )
515
+ (setq-local conf-assignment-sign nil )
535
516
(cond (buffer-file-name
536
517
; ; We set conf-space-keywords directly, but a value which is
537
518
; ; in the local variables list or interactively specified
538
519
; ; (see the function conf-space-keywords) takes precedence.
539
- (setq conf-space-keywords
540
- (assoc-default buffer-file-name conf-space-keywords-alist
541
- 'string-match ))))
520
+ (setq-local conf-space-keywords
521
+ (assoc-default buffer-file-name conf-space-keywords-alist
522
+ # 'string-match ))))
542
523
(conf-space-mode-internal )
543
524
; ; In case the local variables list specifies conf-space-keywords,
544
525
; ; recompute other things from that afterward.
545
- (add-hook 'hack-local-variables-hook 'conf-space-mode-internal nil t ))
526
+ (add-hook 'hack-local-variables-hook # 'conf-space-mode-internal nil t ))
546
527
547
528
;;;### autoload
548
529
(defun conf-space-keywords (keywords )
@@ -553,16 +534,16 @@ See `conf-space-mode'."
553
534
(conf-space-mode ))
554
535
(if (string-equal keywords " " )
555
536
(setq keywords nil ))
556
- (setq conf-space-keywords keywords)
537
+ (setq-local conf-space-keywords keywords)
557
538
(conf-space-mode-internal )
558
539
(run-mode-hooks ))
559
540
560
541
(defun conf-space-mode-internal ()
561
- (make -local-variable ' conf-assignment-regexp)
562
- ( setq conf-assignment-regexp
563
- ( if conf-space-keywords
564
- ( concat " \\ (?: " conf-space-keywords " \\ )[ \t ]+.+?\\ ([ \t ]+\\ |$\\ )" )
565
- " .+?\\ ([ \t ]+\\ |$\\ )" ))
542
+ (setq -local conf-assignment-regexp
543
+ ( if conf-space-keywords
544
+ ( concat " \\ (?: " conf-space-keywords
545
+ " \\ )[ \t ]+.+?\\ ([ \t ]+\\ |$\\ )" )
546
+ " .+?\\ ([ \t ]+\\ |$\\ )" ))
566
547
; ; If Font Lock is already enabled, reenable it with new
567
548
; ; conf-assignment-regexp.
568
549
(when (and font-lock-mode
@@ -596,17 +577,13 @@ For details see `conf-mode'. Example:
596
577
<Multi_key> <exclam> <exclam> : \" \\ 241\" exclamdown
597
578
<Multi_key> <c> <slash> : \" \\ 242\" cent"
598
579
(conf-mode-initialize " #" 'conf-colon-font-lock-keywords )
599
- (set (make-local-variable 'conf-assignment-space )
600
- conf-colon-assignment-space)
601
- (set (make-local-variable 'conf-assignment-column )
602
- conf-colon-assignment-column)
603
- (set (make-local-variable 'conf-assignment-sign )
604
- ?: )
605
- (set (make-local-variable 'conf-assignment-regexp )
606
- " .+?\\ ([ \t ]*:[ \t ]*\\ )" )
607
- (setq imenu-generic-expression
608
- `((" Parameters" " ^[ \t ]*\\ (.+?\\ )[ \t ]*:" 1 )
609
- ,@(cdr imenu-generic-expression))))
580
+ (setq-local conf-assignment-space conf-colon-assignment-space)
581
+ (setq-local conf-assignment-column conf-colon-assignment-column)
582
+ (setq-local conf-assignment-sign ?: )
583
+ (setq-local conf-assignment-regexp " .+?\\ ([ \t ]*:[ \t ]*\\ )" )
584
+ (setq-local imenu-generic-expression
585
+ `((" Parameters" " ^[ \t ]*\\ (.+?\\ )[ \t ]*:" 1 )
586
+ ,@(cdr imenu-generic-expression))))
610
587
611
588
;;;### autoload
612
589
(define-derived-mode conf-ppd-mode conf-colon-mode " Conf[PPD]"
0 commit comments