diff options
| author | Richard M. Stallman | 1995-03-12 19:23:25 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-03-12 19:23:25 +0000 |
| commit | 534a0de54b2eaf6afac6a29cdd2f171b1d0fba13 (patch) | |
| tree | a71ae4e155d2bc8a54be0f5a9169b564bc14b873 | |
| parent | c572e732aeba7bf8530930996ea03a6261d845f5 (diff) | |
| download | emacs-534a0de54b2eaf6afac6a29cdd2f171b1d0fba13.tar.gz emacs-534a0de54b2eaf6afac6a29cdd2f171b1d0fba13.zip | |
(block-comment-start, block-comment-end): New vars.
(indent-for-comment): Handle them.
| -rw-r--r-- | lisp/simple.el | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 8fd370cf71b..b8442fd9b68 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -1902,7 +1902,7 @@ can set the value for a particular mode using that mode's hook.") | |||
| 1902 | (make-variable-buffer-local 'comment-column) | 1902 | (make-variable-buffer-local 'comment-column) |
| 1903 | 1903 | ||
| 1904 | (defconst comment-start nil | 1904 | (defconst comment-start nil |
| 1905 | "*String to insert to start a new comment, or nil if no comment syntax defined.") | 1905 | "*String to insert to start a new comment, or nil if no comment syntax.") |
| 1906 | 1906 | ||
| 1907 | (defconst comment-start-skip nil | 1907 | (defconst comment-start-skip nil |
| 1908 | "*Regexp to match the start of a comment plus everything up to its body. | 1908 | "*Regexp to match the start of a comment plus everything up to its body. |
| @@ -1924,47 +1924,62 @@ the comment's starting delimiter.") | |||
| 1924 | This function is called with no args with point at the beginning of | 1924 | This function is called with no args with point at the beginning of |
| 1925 | the comment's starting delimiter.") | 1925 | the comment's starting delimiter.") |
| 1926 | 1926 | ||
| 1927 | (defconst block-comment-start nil | ||
| 1928 | "*String to insert to start a new comment on a line by itself. | ||
| 1929 | If nil, use `comment-start' instead. | ||
| 1930 | Note that the regular expression `comment-start-skip' should skip this string | ||
| 1931 | as well as the `comment-start' string.") | ||
| 1932 | |||
| 1933 | (defconst block-comment-end nil | ||
| 1934 | "*String to insert to end a new comment on a line by itself. | ||
| 1935 | Should be an empty string if comments are terminated by end-of-line. | ||
| 1936 | If nil, use `comment-end' instead.") | ||
| 1937 | |||
| 1927 | (defun indent-for-comment () | 1938 | (defun indent-for-comment () |
| 1928 | "Indent this line's comment to comment column, or insert an empty comment." | 1939 | "Indent this line's comment to comment column, or insert an empty comment." |
| 1929 | (interactive "*") | 1940 | (interactive "*") |
| 1930 | (beginning-of-line 1) | 1941 | (beginning-of-line 1) |
| 1931 | (if (null comment-start) | 1942 | (let* ((empty (save-excursion (beginning-of-line) |
| 1932 | (error "No comment syntax defined") | 1943 | (looking-at "[ \t]*$"))) |
| 1933 | (let* ((eolpos (save-excursion (end-of-line) (point))) | 1944 | (starter (or (and empty block-comment-start) comment-start)) |
| 1934 | cpos indent begpos) | 1945 | (ender (or (and empty block-comment-end) comment-end))) |
| 1935 | (if (re-search-forward comment-start-skip eolpos 'move) | 1946 | (if (null starter) |
| 1936 | (progn (setq cpos (point-marker)) | 1947 | (error "No comment syntax defined") |
| 1937 | ;; Find the start of the comment delimiter. | 1948 | (let* ((eolpos (save-excursion (end-of-line) (point))) |
| 1938 | ;; If there were paren-pairs in comment-start-skip, | 1949 | cpos indent begpos) |
| 1939 | ;; position at the end of the first pair. | 1950 | (if (re-search-forward comment-start-skip eolpos 'move) |
| 1940 | (if (match-end 1) | 1951 | (progn (setq cpos (point-marker)) |
| 1941 | (goto-char (match-end 1)) | 1952 | ;; Find the start of the comment delimiter. |
| 1942 | ;; If comment-start-skip matched a string with | 1953 | ;; If there were paren-pairs in comment-start-skip, |
| 1943 | ;; internal whitespace (not final whitespace) then | 1954 | ;; position at the end of the first pair. |
| 1944 | ;; the delimiter start at the end of that | 1955 | (if (match-end 1) |
| 1945 | ;; whitespace. Otherwise, it starts at the | 1956 | (goto-char (match-end 1)) |
| 1946 | ;; beginning of what was matched. | 1957 | ;; If comment-start-skip matched a string with |
| 1947 | (skip-syntax-backward " " (match-beginning 0)) | 1958 | ;; internal whitespace (not final whitespace) then |
| 1948 | (skip-syntax-backward "^ " (match-beginning 0))))) | 1959 | ;; the delimiter start at the end of that |
| 1949 | (setq begpos (point)) | 1960 | ;; whitespace. Otherwise, it starts at the |
| 1950 | ;; Compute desired indent. | 1961 | ;; beginning of what was matched. |
| 1951 | (if (= (current-column) | 1962 | (skip-syntax-backward " " (match-beginning 0)) |
| 1952 | (setq indent (if comment-indent-hook | 1963 | (skip-syntax-backward "^ " (match-beginning 0))))) |
| 1953 | (funcall comment-indent-hook) | 1964 | (setq begpos (point)) |
| 1954 | (funcall comment-indent-function)))) | 1965 | ;; Compute desired indent. |
| 1955 | (goto-char begpos) | 1966 | (if (= (current-column) |
| 1956 | ;; If that's different from current, change it. | 1967 | (setq indent (if comment-indent-hook |
| 1957 | (skip-chars-backward " \t") | 1968 | (funcall comment-indent-hook) |
| 1958 | (delete-region (point) begpos) | 1969 | (funcall comment-indent-function)))) |
| 1959 | (indent-to indent)) | 1970 | (goto-char begpos) |
| 1960 | ;; An existing comment? | 1971 | ;; If that's different from current, change it. |
| 1961 | (if cpos | 1972 | (skip-chars-backward " \t") |
| 1962 | (progn (goto-char cpos) | 1973 | (delete-region (point) begpos) |
| 1963 | (set-marker cpos nil)) | 1974 | (indent-to indent)) |
| 1964 | ;; No, insert one. | 1975 | ;; An existing comment? |
| 1965 | (insert comment-start) | 1976 | (if cpos |
| 1966 | (save-excursion | 1977 | (progn (goto-char cpos) |
| 1967 | (insert comment-end)))))) | 1978 | (set-marker cpos nil)) |
| 1979 | ;; No, insert one. | ||
| 1980 | (insert starter) | ||
| 1981 | (save-excursion | ||
| 1982 | (insert ender))))))) | ||
| 1968 | 1983 | ||
| 1969 | (defun set-comment-column (arg) | 1984 | (defun set-comment-column (arg) |
| 1970 | "Set the comment column based on point. | 1985 | "Set the comment column based on point. |