Lines Matching defs:csh

0 ;; csh-mode.el --- csh (and tcsh) script editing mode for Emacs.
8 ;; csh and tcsh script editing mode for Emacs.
11 ;; Put csh-mode.el in some directory in your load-path and load it.
33 ;; csh-mode looks at the first line and indents properly to line
38 ;; 9 Dec 96 DH 1.0: Brought csh-mode up to the level of functionality of
40 ;; 7 Oct 96 CM 0.1: Hacked ksh-mode.el into minimally functional csh-mode.el
49 (defconst csh-mode-version "1.2"
50 "*Version number of this version of csh-mode")
52 (defvar csh-mode-hook
55 "Hook to run each time csh-mode is entered.")
61 (defvar csh-completion-list '())
62 (make-variable-buffer-local 'csh-completion-list)
63 (set-default 'csh-completion-list '())
69 (defvar csh-completion-type-misc 0)
70 (defvar csh-completion-regexp-var "\\([A-Za-z_0-9]+\\)=")
71 (defvar csh-completion-type-var 1)
72 (defvar csh-completion-match-var 1)
73 (defvar csh-completion-regexp-var2 "\\$\\({\\|{#\\)?\\([A-Za-z_0-9]+\\)[#%:}]?")
74 (defvar csh-completion-match-var2 2)
75 (defvar csh-completion-regexp-function
77 (defvar csh-completion-type-function 2)
78 (defvar csh-completion-match-function 2)
84 (defvar csh-indent 4
85 "*Indentation of csh statements with respect to containing block. A value
88 (defvar csh-case-item-offset csh-indent
90 (defvar csh-case-indent nil
92 (defvar csh-comment-regexp "^\\s *#"
94 csh-like languages.")
95 (defvar csh-match-and-tell t
98 (defvar csh-tab-always-indent t
108 (defconst csh-case-default-re
112 (defconst csh-case-item-re "^\\s *\\(case .*\\|default\\):"
115 (defconst csh-end-re "^\\s *end\\b"
118 (defconst csh-endif-re "^\\s *endif\\b"
121 (defconst csh-endsw-re "^\\s *endsw\\b"
124 (defconst csh-else-re "^\\s *\\belse\\(\\b\\|$\\)"
127 (defconst csh-else-if-re "^\\s *\\belse if\\(\\b\\|$\\)"
130 (defconst csh-if-re "^\\s *if\\b.+\\(\\\\\\|\\bthen\\b\\)"
133 (defconst csh-iteration-keywords-re "^[^#\n]*\\s\"*\\b\\(while\\|foreach\\)\\b"
136 (defconst csh-keywords-re
140 (defconst csh-label-re "^\\s *[^!#$\n ]+:"
143 (defconst csh-multiline-re "^.*\\\\$"
146 (defconst csh-switch-re "^\\s *switch\\b"
153 (defvar csh-keywords '("@" "alias" "bg" "break" "breaksw" "case" "cd" "chdir"
168 (defconst csh-font-lock-keywords
215 (mapconcat 'identity csh-keywords "\\>\\|\\<")
220 (put 'csh-mode 'font-lock-keywords 'csh-font-lock-keywords)
226 (defvar csh-mode-abbrev-table nil
227 "Abbrev table used while in csh mode.")
228 (define-abbrev-table 'csh-mode-abbrev-table ())
230 (defvar csh-mode-map nil
231 "Keymap used in csh mode")
232 (if csh-mode-map
234 (setq csh-mode-map (make-sparse-keymap))
235 ;;(define-key csh-mode-map "\177" 'backward-delete-char-untabify)
236 (define-key csh-mode-map "\C-c\t" 'csh-completion-init-and-pickup)
237 (define-key csh-mode-map "\C-j" 'reindent-then-newline-and-indent)
238 (define-key csh-mode-map "\e\t" 'csh-complete-symbol)
239 (define-key csh-mode-map "\n" 'reindent-then-newline-and-indent)
240 (define-key csh-mode-map '[return] 'reindent-then-newline-and-indent)
241 (define-key csh-mode-map "\t" 'csh-indent-command)
242 ;;(define-key csh-mode-map "\t" 'csh-indent-line)
245 (defvar csh-mode-syntax-table nil
246 "Syntax table used while in csh mode.")
247 (if csh-mode-syntax-table
251 (setq csh-mode-syntax-table (make-syntax-table))
252 (modify-syntax-entry ?& "." csh-mode-syntax-table) ; & -punctuation
253 (modify-syntax-entry ?* "." csh-mode-syntax-table) ; * -punctuation
254 (modify-syntax-entry ?- "." csh-mode-syntax-table) ; - -punctuation
255 (modify-syntax-entry ?= "." csh-mode-syntax-table) ; = -punctuation
256 (modify-syntax-entry ?+ "." csh-mode-syntax-table) ; + -punctuation
257 (modify-syntax-entry ?| "." csh-mode-syntax-table) ; | -punctuation
258 (modify-syntax-entry ?< "." csh-mode-syntax-table) ; < -punctuation
259 (modify-syntax-entry ?> "." csh-mode-syntax-table) ; > -punctuation
260 (modify-syntax-entry ?/ "." csh-mode-syntax-table) ; / -punctuation
261 (modify-syntax-entry ?\' "\"" csh-mode-syntax-table) ; ' -string quote
262 (modify-syntax-entry ?. "w" csh-mode-syntax-table) ; . -word constituent
263 (modify-syntax-entry ?? "w" csh-mode-syntax-table) ; ? -word constituent
266 (modify-syntax-entry ?\n "> 1" csh-mode-syntax-table) ; # -word constituent
269 (modify-syntax-entry ? " 1" csh-mode-syntax-table) ;
272 (modify-syntax-entry ?\t " 1" csh-mode-syntax-table) ; # -word constituent
275 (modify-syntax-entry ?# "w 2" csh-mode-syntax-table) ; # -word constituent
282 (defun csh-current-line ()
289 (defun csh-get-compound-level
317 (csh-get-compound-level begin-re end-re
325 (cons nest-column (csh-current-line)))
334 (defun csh-get-nest-level ()
347 (looking-at csh-multiline-re)))
348 (not (looking-at csh-comment-regexp)))
350 (csh-current-line)))
355 (cons (current-indentation) (csh-current-line))
361 (defun csh-get-nester-column (nest-line)
367 (start-line (csh-current-line)))
370 (cond ((looking-at csh-case-item-re)
375 (cond ((re-search-forward csh-switch-re fence-post t)
378 (+ (current-indentation) csh-case-item-offset))
380 ((re-search-forward csh-case-item-re fence-post t)
389 (- (current-indentation) csh-case-item-offset))
400 ((and (looking-at csh-multiline-re)
403 (looking-at csh-multiline-re)))
423 ((re-search-forward csh-keywords-re fence-post t)
425 (if (looking-at csh-switch-re)
426 (+ (current-indentation) csh-case-item-offset)
428 (if (null csh-indent)
429 2 csh-indent)
432 ((re-search-forward csh-case-default-re fence-post t)
433 (if (null csh-indent)
439 (+ (current-indentation) csh-indent))
444 ((looking-at csh-case-item-re)
445 (if (null csh-case-indent)
447 (re-search-forward csh-case-item-re fence-post t)
450 (+ (current-indentation) csh-case-indent)))
455 ((csh-looking-at-label)
456 (+ (current-indentation) csh-indent))
469 (defun csh-indent-command ()
471 csh-tab-always-indent customization"
477 (csh-indent-line))
478 (csh-tab-always-indent
480 (csh-indent-line)))
485 (defun csh-indent-line ()
498 (level-list (csh-get-nest-level)) ; Where to nest against
501 (nester-column (csh-get-nester-column (cdr level-list)))
502 (struct-match (csh-match-structure-and-reindent))
534 (defun csh-indent-region (start end)
539 (let (csh-match-and-tell
547 (csh-indent-line))
556 (defun csh-line-to-string ()
565 (defun csh-looking-at-label ()
568 (looking-at csh-label-re)
571 (defun csh-match-indent-level (begin-re end-re)
578 (csh-get-compound-level begin-re end-re (point))
583 (if csh-match-and-tell
590 (if csh-match-and-tell
593 (message "Matched ... %s" (csh-line-to-string))
595 ) ;; if csh-match-and-tell
600 ) ;; defun csh-match-indent-level
602 (defun csh-match-structure-and-reindent ()
605 if csh-match-and-tell is non-nil the matching structure will echo in
611 (cond ((looking-at csh-else-re)
612 (csh-match-indent-level csh-if-re csh-endif-re))
613 ((looking-at csh-else-if-re)
614 (csh-match-indent-level csh-if-re csh-endif-re))
615 ((looking-at csh-endif-re)
616 (csh-match-indent-level csh-if-re csh-endif-re))
617 ((looking-at csh-end-re)
618 (csh-match-indent-level csh-iteration-keywords-re csh-end-re))
619 ((looking-at csh-endsw-re)
620 (csh-match-indent-level csh-switch-re csh-endsw-re))
621 ((csh-looking-at-label)
631 (defun csh-mode ()
632 "csh-mode 2.0 - Major mode for editing csh and tcsh scripts.
634 \\{csh-mode-map}
636 csh-indent
637 Indentation of csh statements with respect to containing block.
639 csh-case-indent
643 csh-case-item-offset
646 csh-tab-always-indent
651 csh-match-and-tell
655 csh-comment-regexp
657 csh-like languages. Default value is \"\^\\\\s *#\".
661 (setq csh-indent default-tab-width)
667 bar # <-- csh-group-offset is additive to csh-indent
672 (setq csh-indent default-tab-width)
673 (setq csh-group-offset (- 0 csh-indent))
684 (setq csh-case-item-offset 1)
685 (setq csh-case-indent nil)
690 foo) bar # <-- csh-case-item-offset
691 baz;; # <-- csh-case-indent aligns with \")\"
697 (setq csh-case-item-offset 1)
698 (setq csh-case-indent 6)
703 foo) bar # <-- csh-case-item-offset
704 baz;; # <-- csh-case-indent
711 Put csh-mode.el in some directory in your load-path.
717 '(\"\\\\.csh$\" . csh-mode)
718 '(\"\\\\.login\" . csh-mode))))
720 (setq csh-mode-hook
723 (setq csh-indent 8)
724 (setq csh-tab-always-indent t)
725 (setq csh-match-and-tell t)
726 (setq csh-align-to-keyword t) ;; Turn on keyword alignment
730 (use-local-map csh-mode-map)
731 (setq major-mode 'csh-mode)
733 (setq local-abbrev-table csh-mode-abbrev-table)
734 (set-syntax-table csh-mode-syntax-table)
736 (setq indent-line-function 'csh-indent-line)
738 (setq indent-region-function 'csh-indent-region)
750 (setq font-lock-keywords csh-font-lock-keywords)
753 (run-hooks 'csh-mode-hook)
762 (defun csh-addto-alist (completion type)
763 (setq csh-completion-list
764 (append csh-completion-list
767 (defun csh-bol-point ()
772 (defun csh-complete-symbol ()
798 (equal (cdr sym) csh-completion-type-function)))
814 csh-completion-type-var)))
820 (completion (try-completion pattern csh-completion-list predicate)))
839 (let ((list (all-completions pattern csh-completion-list predicate))
850 (defun csh-completion-init-and-pickup ()
853 (csh-completion-list-init)
854 (csh-pickup-all)))
859 (defun csh-completion-list-init ()
861 (setq csh-completion-list
863 (cons "break" csh-completion-type-misc)
864 (cons "breaksw" csh-completion-type-misc)
865 (cons "case" csh-completion-type-misc)
866 (cons "continue" csh-completion-type-misc)
867 (cons "endif" csh-completion-type-misc)
868 (cons "exit" csh-completion-type-misc)
869 (cons "foreach" csh-completion-type-misc)
870 (cons "if" csh-completion-type-misc)
871 (cons "while" csh-completion-type-misc))))
873 (defun csh-eol-point ()
878 (defun csh-pickup-all ()
881 (csh-pickup-completion-driver (point-min) (point-max) t))
883 (defun csh-pickup-completion (regexp type match pmin pmax)
896 (setq obj (assoc kw csh-completion-list))
902 (csh-addto-alist kw type))))))
905 (defun csh-pickup-completion-driver (pmin pmax message)
906 "Driver routine for csh-pickup-completion."
911 (csh-pickup-completion csh-completion-regexp-var
912 csh-completion-type-var
913 csh-completion-match-var
916 (csh-pickup-completion csh-completion-regexp-var2
917 csh-completion-type-var
918 csh-completion-match-var2
921 (csh-pickup-completion csh-completion-regexp-function
922 csh-completion-type-function
923 csh-completion-match-function
928 (defun csh-pickup-this-line ()
931 (csh-pickup-completion-driver (csh-bol-point) (csh-eol-point) nil))
934 (provide 'csh-mode)
935 ;;; csh-mode.el ends here