X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/cd21c04ac9ab2b67f1d67b700453e19370da42fa..577bf5d26e8835144005a0505e2ecc611369f92f:/lisp/progmodes/tcl.el diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el index 38867b96ec..6965dea9fc 100644 --- a/lisp/progmodes/tcl.el +++ b/lisp/progmodes/tcl.el @@ -1,12 +1,11 @@ ;;; tcl.el --- Tcl code editing commands for Emacs -;; Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +;; Copyright (C) 1994,98,1999,2000,01,02,2003,2004 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Author: Tom Tromey ;; Chris Lindblad ;; Keywords: languages tcl modes -;; Version: $Revision: 1.69 $ ;; This file is part of GNU Emacs. @@ -122,20 +121,17 @@ (defcustom tcl-indent-level 4 "*Indentation of Tcl statements with respect to containing block." - :group 'tcl :type 'integer) (defcustom tcl-continued-indent-level 4 "*Indentation of continuation line relative to first line of command." - :group 'tcl :type 'integer) (defcustom tcl-auto-newline nil "*Non-nil means automatically newline before and after braces you insert." - :group 'tcl :type 'boolean) -(defcustom tcl-tab-always-indent t +(defcustom tcl-tab-always-indent tab-always-indent "*Control effect of TAB key. If t (the default), always indent current line. If nil and point is not in the indentation area at the beginning of @@ -149,7 +145,6 @@ to take place: 4. Move forward to end of line, indenting if necessary. 5. Create an empty comment. 6. Move backward to start of comment, indenting if necessary." - :group 'tcl :type '(choice (const :tag "Always" t) (const :tag "Beginning only" nil) (const :tag "Maybe move or make or delete comment" 'tcl))) @@ -163,27 +158,22 @@ meaning that the choice between `backslash' and `quote' should be made depending on the number of hashes inserted; or nil, meaning that no quoting should be done. Any other value for this variable is taken to mean `smart'. The default is nil." - :group 'tcl :type '(choice (const backslash) (const quote) (const smart) (const nil))) (defcustom tcl-help-directory-list nil "*List of topmost directories containing TclX help files." - :group 'tcl :type '(repeat directory)) (defcustom tcl-use-smart-word-finder t "*If not nil, use smart way to find current word, for Tcl help feature." - :group 'tcl :type 'boolean) (defcustom tcl-application "wish" "*Name of Tcl program to run in inferior Tcl mode." - :group 'tcl :type 'string) (defcustom tcl-command-switches nil "*List of switches to supply to the `tcl-application' program." - :group 'tcl :type '(repeat string)) (defcustom tcl-prompt-regexp "^\\(% \\|\\)" @@ -192,7 +182,6 @@ If nil, the prompt is the name of the application with \">\" appended. The default is \"^\\(% \\|\\)\", which will match the default primary and secondary prompts for tclsh and wish." - :group 'tcl :type 'regexp) (defcustom inferior-tcl-source-command "source %s\n" @@ -201,7 +190,6 @@ This format string should use `%s' to substitute a file name and should result in a Tcl expression that will command the inferior Tcl to load that file. The filename will be appropriately quoted for Tcl." - :group 'tcl :type 'string) ;; @@ -318,7 +306,7 @@ have three inferior Lisps running: If you do a \\[tcl-eval-defun] command on some Lisp source code, what process do you send it to? -- If you're in a process buffer (foo, bar, or *inferior-tcl*), +- If you're in a process buffer (foo, bar, or *inferior-tcl*), you send it to that process. - If you're in some other buffer (e.g., a source file), you send it to the process attached to buffer `inferior-tcl-buffer'. @@ -437,32 +425,20 @@ argument is ignored (for indentation purposes). The second argument is a Tcl expression, and the last argument is Tcl commands.") (defvar tcl-explain-indentation nil - "If not `nil', debugging message will be printed during indentation.") + "If non-nil, debugging message will be printed during indentation.") -;; Its pretty bogus to have to do this, but there is no easier way to -;; say "match not syntax-1 and not syntax-2". Too bad you can't put -;; \s in [...]. This sickness is used in Emacs 19 to match a defun -;; starter. (It is used for this in v18 as well). -;;(defconst tcl-omit-ws-regexp -;; (concat "^\\(\\s" -;; (mapconcat 'char-to-string "w_.()\"\\$'/" "\\|\\s") -;; "\\)\\S(*") -;; "Regular expression that matches everything except space, comment -;;starter, and comment ender syntax codes.") - -;; FIXME? Instead of using the hairy regexp above, we just use a -;; simple one. -;;(defconst tcl-omit-ws-regexp "^[^] \t\n#}]\\S(*" -;; "Regular expression used in locating function definitions.") - -;; Here's another stab. I think this one actually works. Now the -;; problem seems to be that there is a bug in Emacs 19.22 where -;; end-of-defun doesn't really use the brace matching the one that -;; trails defun-prompt-regexp. -;; ?? Is there a bug now ?? -(defconst tcl-omit-ws-regexp "^[^ \t\n#}][^\n}]+}*[ \t]+") +;; Here's another stab. I think this one actually works. +;; We have to be careful that the open-brace following this regexp +;; is indeed the one corresponding to the function's body so +;; that end-of-defun works correctly. Tricky cases are: +;; proc foo { {arg1 def} arg2 } { +;; as well as +;; proc foo { \n {arg1 def} \n arg2 } { +;; The current setting handles the first case properly but not the second. +;; It also fails if `proc' is not in column-0 (e.g. it's in a namespace). +(defconst tcl-omit-ws-regexp "^[^] \t\n#}].+[ \t]+") @@ -494,7 +470,7 @@ Uses variables `tcl-proc-regexp' and `tcl-keyword-list'." ;; FIXME consider using "not word or symbol", not ;; "whitespace". (cons (concat "\\(\\s-\\|^\\)" - ;; FIXME Use regexp-quote? + ;; FIXME Use regexp-quote? (regexp-opt tcl-keyword-list t) "\\(\\s-\\|$\\)") 2)))) @@ -543,8 +519,7 @@ documentation for details): If not nil, use a smarter, Tcl-specific way to find the current word when looking up help on a Tcl command. -Turning on Tcl mode calls the value of the variable `tcl-mode-hook' -with no args, if that value is non-nil. Read the documentation for +Turning on Tcl mode runs `tcl-mode-hook'. Read the documentation for `tcl-mode-hook' to see what kinds of interesting hook functions already exist. @@ -560,7 +535,8 @@ Commands: ;; (setq require-final-newline t) (set (make-local-variable 'comment-start) "# ") - (set (make-local-variable 'comment-start-skip) "#+ *") + (set (make-local-variable 'comment-start-skip) + "\\(\\(^\\|[;{[]\\)\\s-*\\)#+ *") (set (make-local-variable 'comment-end) "") (set (make-local-variable 'outline-regexp) ".") @@ -572,8 +548,8 @@ Commands: (parse-sexp-lookup-properties . t))) (set (make-local-variable 'imenu-generic-expression) - 'tcl-imenu-generic-expression) - + tcl-imenu-generic-expression) + ;; Settings for new dabbrev code. (set (make-local-variable 'dabbrev-case-fold-search) nil) (set (make-local-variable 'dabbrev-case-replace) nil) @@ -789,7 +765,7 @@ Returns nil if line starts inside a string, t if in a comment." (beginning-of-line) (let* ((indent-point (point)) (case-fold-search nil) - (continued-line + (continued-line (save-excursion (if (bobp) nil @@ -890,7 +866,7 @@ Returns nil if line starts inside a string, t if in a comment." (contain-stack (list (point))) (case-fold-search nil) outer-loop-done inner-loop-done state ostate - this-indent last-sexp continued-line + this-indent continued-line (next-depth 0) last-depth) (save-excursion @@ -910,9 +886,6 @@ Returns nil if line starts inside a string, t if in a comment." (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) nil nil state)) (setq next-depth (car state)) - (if (and (car (cdr (cdr state))) - (>= (car (cdr (cdr state))) 0)) - (setq last-sexp (car (cdr (cdr state))))) (if (or (nth 4 ostate)) (tcl-indent-line)) (if (or (nth 3 state)) @@ -929,21 +902,19 @@ Returns nil if line starts inside a string, t if in a comment." (setq indent-stack (cdr indent-stack) contain-stack (cdr contain-stack) last-depth (1- last-depth))) - (if (/= last-depth next-depth) - (setq last-sexp nil)) ;; Add levels for any parens that were started in this line. (while (< last-depth next-depth) (setq indent-stack (cons nil indent-stack) contain-stack (cons nil contain-stack) last-depth (1+ last-depth))) (if (null (car contain-stack)) - (setcar contain-stack + (setcar contain-stack (or (car (cdr state)) (save-excursion (forward-sexp -1) (point))))) (forward-line 1) - (setq continued-line + (setq continued-line (save-excursion (backward-char) (= (preceding-char) ?\\))) @@ -969,14 +940,14 @@ Returns nil if line starts inside a string, t if in a comment." (setq this-indent (- this-indent 1)))) ;; Put chosen indentation into effect. (or (null this-indent) - (= (current-column) - (if continued-line + (= (current-column) + (if continued-line (+ this-indent tcl-indent-level) this-indent)) (progn (delete-region (point) (progn (beginning-of-line) (point))) - (indent-to - (if continued-line + (indent-to + (if continued-line (+ this-indent tcl-indent-level) this-indent))))))))) ) @@ -1133,15 +1104,13 @@ See documentation for function `inferior-tcl-mode' for more information." (list (if current-prefix-arg (read-string "Run Tcl: " tcl-application) tcl-application))) - (if (not (comint-check-proc "*inferior-tcl*")) - (progn - (set-buffer (apply (function make-comint) "inferior-tcl" cmd nil - tcl-command-switches)) - (inferior-tcl-mode))) - (make-local-variable 'tcl-application) - (setq tcl-application cmd) + (unless (comint-check-proc "*inferior-tcl*") + (set-buffer (apply (function make-comint) "inferior-tcl" cmd nil + tcl-command-switches)) + (inferior-tcl-mode)) + (set (make-local-variable 'tcl-application) cmd) (setq inferior-tcl-buffer "*inferior-tcl*") - (switch-to-buffer "*inferior-tcl*")) + (pop-to-buffer "*inferior-tcl*")) (defalias 'run-tcl 'inferior-tcl) @@ -1538,4 +1507,5 @@ The first line is assumed to look like \"#!.../program ...\"." (provide 'tcl) +;;; arch-tag: 8a032554-c3ef-422e-b84c-acec0522179d ;;; tcl.el ends here