aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey1994-04-23 16:23:36 +0000
committerTom Tromey1994-04-23 16:23:36 +0000
commit95338744d6d217c3b6db321fa0333a619fdb1d06 (patch)
tree2a27a9f57512f47fd72134b6691efdac648142d7
parent072c3cd228fd4df189dadc5ab9fc2cd56bfaad63 (diff)
downloademacs-95338744d6d217c3b6db321fa0333a619fdb1d06.tar.gz
emacs-95338744d6d217c3b6db321fa0333a619fdb1d06.zip
Wrote tcl-indent-for-comment
-rw-r--r--lisp/progmodes/tcl.el138
1 files changed, 92 insertions, 46 deletions
diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el
index 02466483e19..9b850e0b4da 100644
--- a/lisp/progmodes/tcl.el
+++ b/lisp/progmodes/tcl.el
@@ -6,7 +6,7 @@
6;; Author: Tom Tromey <tromey@busco.lanl.gov> 6;; Author: Tom Tromey <tromey@busco.lanl.gov>
7;; Chris Lindblad <cjl@lcs.mit.edu> 7;; Chris Lindblad <cjl@lcs.mit.edu>
8;; Keywords: languages tcl modes 8;; Keywords: languages tcl modes
9;; Version: $Revision: 1.4 $ 9;; Version: $Revision: 1.5 $
10 10
11;; This file is part of GNU Emacs. 11;; This file is part of GNU Emacs.
12 12
@@ -33,10 +33,10 @@
33;; (setq auto-mode-alist (append '(("\\.tcl$" . tcl-mode)) auto-mode-alist)) 33;; (setq auto-mode-alist (append '(("\\.tcl$" . tcl-mode)) auto-mode-alist))
34;; 34;;
35;; If you plan to use the interface to the TclX help files, you must 35;; If you plan to use the interface to the TclX help files, you must
36;; set the variable tcl-help-directory to point to the topmost 36;; set the variable tcl-help-directory-list to point to the topmost
37;; directory containing the TclX help files. Eg: 37;; directories containing the TclX help files. Eg:
38;; 38;;
39;; (setq tcl-help-directory "/usr/local/lib/tclx/help") 39;; (setq tcl-help-directory-list '("/usr/local/lib/tclx/help"))
40;; 40;;
41;; Also you will want to add the following to your .emacs: 41;; Also you will want to add the following to your .emacs:
42;; 42;;
@@ -51,7 +51,7 @@
51;; LCD Archive Entry: 51;; LCD Archive Entry:
52;; tcl|Tom Tromey|tromey@busco.lanl.gov| 52;; tcl|Tom Tromey|tromey@busco.lanl.gov|
53;; Major mode for editing Tcl| 53;; Major mode for editing Tcl|
54;; $Date: 1994/04/07 00:23:36 $|$Revision: 1.4 $|~/modes/tcl.el.Z| 54;; $Date: 1994/04/07 17:11:03 $|$Revision: 1.5 $|~/modes/tcl.el.Z|
55 55
56;; CUSTOMIZATION NOTES: 56;; CUSTOMIZATION NOTES:
57;; * tcl-proc-list can be used to customize a list of things that 57;; * tcl-proc-list can be used to customize a list of things that
@@ -64,6 +64,8 @@
64;; according to context. 64;; according to context.
65 65
66;; Change log: 66;; Change log:
67;; $Log$
68;;
67;; 18-Mar-1994 Tom Tromey Fourth beta release. 69;; 18-Mar-1994 Tom Tromey Fourth beta release.
68;; Added {un,}comment-region to menu. Idea from 70;; Added {un,}comment-region to menu. Idea from
69;; Mike Scheidler <c23mts@kocrsv01.delcoelect.com> 71;; Mike Scheidler <c23mts@kocrsv01.delcoelect.com>
@@ -177,6 +179,10 @@
177;; * Trailing \ will eat blank lines. Should deal with this. 179;; * Trailing \ will eat blank lines. Should deal with this.
178;; (this would help catch some potential bugs). 180;; (this would help catch some potential bugs).
179;; * Inferior should display in half the screen, not the whole screen. 181;; * Inferior should display in half the screen, not the whole screen.
182;; * M-; should do the right thing about putting a ";" at the end of a line.
183;; * Indentation should deal with "switch".
184;; * Consider writing code to find help files automatically (for
185;; common cases).
180 186
181 187
182 188
@@ -227,8 +233,8 @@ made depending on the number of hashes inserted; or nil, meaning that
227no quoting should be done. Any other value for this variable is 233no quoting should be done. Any other value for this variable is
228taken to mean 'smart. The default is 'smart.") 234taken to mean 'smart. The default is 'smart.")
229 235
230(defvar tcl-help-directory nil 236(defvar tcl-help-directory-list nil
231 "*Name of topmost directory containing TclX help files") 237 "*List of topmost directories containing TclX help files")
232 238
233(defvar tcl-use-smart-word-finder t 239(defvar tcl-use-smart-word-finder t
234 "*If not nil, use a better way of finding the current word when 240 "*If not nil, use a better way of finding the current word when
@@ -297,6 +303,7 @@ quoted for Tcl.")
297 (define-key tcl-mode-map "\e\C-q" 'indent-tcl-exp) 303 (define-key tcl-mode-map "\e\C-q" 'indent-tcl-exp)
298 (define-key tcl-mode-map "\177" 'backward-delete-char-untabify) 304 (define-key tcl-mode-map "\177" 'backward-delete-char-untabify)
299 (define-key tcl-mode-map "\t" 'tcl-indent-command) 305 (define-key tcl-mode-map "\t" 'tcl-indent-command)
306 (define-key tcl-mode-map "\M-;" 'tcl-indent-for-comment)
300 (define-key tcl-mode-map "\M-\C-x" 'tcl-eval-defun) 307 (define-key tcl-mode-map "\M-\C-x" 'tcl-eval-defun)
301 (and (fboundp 'comment-region) 308 (and (fboundp 'comment-region)
302 (define-key tcl-mode-map "\C-c\C-c" 'comment-region)) 309 (define-key tcl-mode-map "\C-c\C-c" 'comment-region))
@@ -802,7 +809,7 @@ from the following list to take place:
802 (interactive "p") 809 (interactive "p")
803 (cond 810 (cond
804 ((not tcl-tab-always-indent) 811 ((not tcl-tab-always-indent)
805 ;; Indent if in identation area, otherwise insert TAB. 812 ;; Indent if in indentation area, otherwise insert TAB.
806 (if (<= (current-column) (current-indentation)) 813 (if (<= (current-column) (current-indentation))
807 (tcl-indent-line) 814 (tcl-indent-line)
808 (self-insert-command arg))) 815 (self-insert-command arg)))
@@ -846,17 +853,8 @@ from the following list to take place:
846 (goto-char eolpoint) 853 (goto-char eolpoint)
847 (tcl-indent-line)) 854 (tcl-indent-line))
848 ((not comment-p) 855 ((not comment-p)
849 ;; Create an empty comment (since there isn't one on this
850 ;; line). If line is not blank, make sure we insert a ";"
851 ;; first.
852 (beginning-of-line)
853 (if (/= (point) eolpoint)
854 (progn
855 (goto-char eolpoint)
856 (or (tcl-real-command-p)
857 (insert ";"))))
858 (tcl-indent-line) 856 (tcl-indent-line)
859 (indent-for-comment)) 857 (tcl-indent-for-comment))
860 (t 858 (t
861 ;; Go to start of comment. We don't leave point where it is 859 ;; Go to start of comment. We don't leave point where it is
862 ;; because we want to skip comment-start-skip. 860 ;; because we want to skip comment-start-skip.
@@ -1157,6 +1155,8 @@ Returns nil if line starts inside a string, t if in a comment."
1157;; Interfaces to other packages. 1155;; Interfaces to other packages.
1158;; 1156;;
1159 1157
1158(autoload 'imenu-progress-message "imenu" "" nil 'macro)
1159
1160(defun tcl-imenu-create-index-function () 1160(defun tcl-imenu-create-index-function ()
1161 "Generate alist of indices for imenu." 1161 "Generate alist of indices for imenu."
1162 (let ((re (concat tcl-proc-regexp "\\([^ \t\n{]+\\)")) 1162 (let ((re (concat tcl-proc-regexp "\\([^ \t\n{]+\\)"))
@@ -1468,42 +1468,43 @@ of comment."
1468;; Help-related code. 1468;; Help-related code.
1469;; 1469;;
1470 1470
1471(defvar tcl-help-saved-dir nil 1471(defvar tcl-help-saved-dirs nil
1472 "Saved help directory. If `tcl-help-directory' changes, this allows 1472 "Saved help directories.
1473tcl-help-on-word to update the alist") 1473If `tcl-help-directory-list' changes, this allows `tcl-help-on-word'
1474to update the alist.")
1474 1475
1475(defvar tcl-help-alist nil 1476(defvar tcl-help-alist nil
1476 "Alist with command names as keys and filenames as values.") 1477 "Alist with command names as keys and filenames as values.")
1477 1478
1478(defun tcl-help-snarf-commands (dir) 1479(defun tcl-help-snarf-commands (dirlist)
1479 "Build alist of commands and filenames. There is probably a much 1480 "Build alist of commands and filenames."
1480better implementation of this, but I'm too tired to think of it right 1481 (while dirlist
1481now." 1482 (let ((files (directory-files (car dirlist) t)))
1482 (let ((files (directory-files dir t))) 1483 (while files
1483 (while files 1484 (if (and (file-directory-p (car files))
1484 (if (and (file-directory-p (car files)) 1485 (not
1485 (not 1486 (let ((fpart (file-name-nondirectory (car files))))
1486 (let ((fpart (file-name-nondirectory (car files)))) 1487 (or (equal fpart ".")
1487 (or (equal fpart ".") 1488 (equal fpart "..")))))
1488 (equal fpart ".."))))) 1489 (let ((matches (directory-files (car files) t)))
1489 (let ((matches (directory-files (car files) t))) 1490 (while matches
1490 (while matches 1491 (or (file-directory-p (car matches))
1491 (or (file-directory-p (car matches)) 1492 (setq tcl-help-alist
1492 (setq tcl-help-alist 1493 (cons
1493 (cons 1494 (cons (file-name-nondirectory (car matches))
1494 (cons (file-name-nondirectory (car matches)) 1495 (car matches))
1495 (car matches)) 1496 tcl-help-alist)))
1496 tcl-help-alist))) 1497 (setq matches (cdr matches)))))
1497 (setq matches (cdr matches))))) 1498 (setq files (cdr files))))
1498 (setq files (cdr files))))) 1499 (setq dirlist (cdr dirlist))))
1499 1500
1500(defun tcl-reread-help-files () 1501(defun tcl-reread-help-files ()
1501 "Set up to re-read files, and then do it." 1502 "Set up to re-read files, and then do it."
1502 (interactive) 1503 (interactive)
1503 (message "Building Tcl help file index...") 1504 (message "Building Tcl help file index...")
1504 (setq tcl-help-saved-dir tcl-help-directory) 1505 (setq tcl-help-saved-dirs tcl-help-directory-list)
1505 (setq tcl-help-alist nil) 1506 (setq tcl-help-alist nil)
1506 (tcl-help-snarf-commands tcl-help-directory) 1507 (tcl-help-snarf-commands tcl-help-directory-list)
1507 (message "Building Tcl help file index...done")) 1508 (message "Building Tcl help file index...done"))
1508 1509
1509(defun tcl-current-word (flag) 1510(defun tcl-current-word (flag)
@@ -1530,7 +1531,7 @@ Prefix argument means invert sense of `tcl-use-smart-word-finder'."
1530 (interactive 1531 (interactive
1531 (list 1532 (list
1532 (progn 1533 (progn
1533 (if (not (string= tcl-help-directory tcl-help-saved-dir)) 1534 (if (not (equal tcl-help-directory-list tcl-help-saved-dirs))
1534 (tcl-reread-help-files)) 1535 (tcl-reread-help-files))
1535 (let ((word (tcl-current-word 1536 (let ((word (tcl-current-word
1536 (if current-prefix-arg 1537 (if current-prefix-arg
@@ -1542,7 +1543,7 @@ Prefix argument means invert sense of `tcl-use-smart-word-finder'."
1542 (format "Help on Tcl command (default %s): " word)) 1543 (format "Help on Tcl command (default %s): " word))
1543 tcl-help-alist nil t))) 1544 tcl-help-alist nil t)))
1544 current-prefix-arg)) 1545 current-prefix-arg))
1545 (if (not (string= tcl-help-directory tcl-help-saved-dir)) 1546 (if (not (equal tcl-help-directory-list tcl-help-saved-dirs))
1546 (tcl-reread-help-files)) 1547 (tcl-reread-help-files))
1547 (if (string= command "") 1548 (if (string= command "")
1548 (setq command (tcl-current-word 1549 (setq command (tcl-current-word
@@ -1716,12 +1717,57 @@ styles."
1716 (insert "\\")) 1717 (insert "\\"))
1717 (forward-char)))))) 1718 (forward-char))))))
1718 1719
1720(defun tcl-indent-for-comment ()
1721 "Indent this line's comment to comment column, or insert an empty comment.
1722Is smart about syntax of Tcl comments.
1723Parts of this were taken from indent-for-comment (simple.el)."
1724 (interactive "*")
1725 (end-of-line)
1726 (or (tcl-in-comment)
1727 (progn
1728 ;; Not in a comment, so we have to insert one. Create an
1729 ;; empty comment (since there isn't one on this line). If
1730 ;; line is not blank, make sure we insert a ";" first.
1731 (skip-chars-backward " \t")
1732 (let ((eolpoint (point)))
1733 (beginning-of-line)
1734 (if (/= (point) eolpoint)
1735 (progn
1736 (goto-char eolpoint)
1737 (or (tcl-real-command-p)
1738 (progn
1739 (insert ";# ")
1740 (backward-char))))))))
1741 ;; Point is just after the "#" starting a comment. Move it as
1742 ;; appropriate.
1743 (let* ((indent (if comment-indent-hook
1744 (funcall comment-indent-hook)
1745 (funcall comment-indent-function)))
1746 (begpos (progn
1747 (backward-char)
1748 (point))))
1749 (if (/= begpos indent)
1750 (progn
1751 (skip-chars-backward " \t" (save-excursion
1752 (beginning-of-line)
1753 (point)))
1754 (delete-region (point) begpos)
1755 (indent-to indent)))
1756 (looking-at comment-start-skip) ; Always true.
1757 (goto-char (match-end 0))
1758 ;; I don't like the effect of the next two.
1759 ;;(skip-chars-backward " \t" (match-beginning 0))
1760 ;;(skip-chars-backward "^ \t" (match-beginning 0))
1761 ))
1762
1719;; The following was inspired by the Tcl editing mode written by 1763;; The following was inspired by the Tcl editing mode written by
1720;; Gregor Schmid <schmid@fb3-s7.math.TU-Berlin.DE>. His version also 1764;; Gregor Schmid <schmid@fb3-s7.math.TU-Berlin.DE>. His version also
1721;; attempts to snarf the command line options from the command line, 1765;; attempts to snarf the command line options from the command line,
1722;; but I didn't think that would really be that helpful (doesn't seem 1766;; but I didn't think that would really be that helpful (doesn't seem
1723;; like it owould be right enough. His version also looks for the 1767;; like it owould be right enough. His version also looks for the
1724;; "#!/bin/csh ... exec" hack, but that seemed even less useful. 1768;; "#!/bin/csh ... exec" hack, but that seemed even less useful.
1769;; FIXME should make sure that the application mentioned actually
1770;; exists.
1725(defun tcl-guess-application () 1771(defun tcl-guess-application ()
1726 "Attempt to guess Tcl application by looking at first line. 1772 "Attempt to guess Tcl application by looking at first line.
1727The first line is assumed to look like \"#!.../program ...\"." 1773The first line is assumed to look like \"#!.../program ...\"."