diff options
| author | Richard M. Stallman | 1992-07-22 01:36:20 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-07-22 01:36:20 +0000 |
| commit | 1832dbd149ce63e0a893480709231a6add1c819c (patch) | |
| tree | c3eee3d6fdde63952259b74b7f4a87e1d855f7e1 | |
| parent | 0c280127f51f9b5b17e4cb5bba80fe78c2c06c6d (diff) | |
| download | emacs-1832dbd149ce63e0a893480709231a6add1c819c.tar.gz emacs-1832dbd149ce63e0a893480709231a6add1c819c.zip | |
*** empty log message ***
| -rw-r--r-- | lisp/add-log.el | 128 | ||||
| -rw-r--r-- | lisp/progmodes/c-mode.el | 122 |
2 files changed, 154 insertions, 96 deletions
diff --git a/lisp/add-log.el b/lisp/add-log.el index fe8dfcb37ba..c1c4f1795b7 100644 --- a/lisp/add-log.el +++ b/lisp/add-log.el | |||
| @@ -75,8 +75,8 @@ Third arg OTHER-WINDOW non-nil means visit in other window." | |||
| 75 | buffer-file-name) | 75 | buffer-file-name) |
| 76 | (substring buffer-file-name (match-end 0)) | 76 | (substring buffer-file-name (match-end 0)) |
| 77 | (file-name-nondirectory buffer-file-name)))) | 77 | (file-name-nondirectory buffer-file-name)))) |
| 78 | ;; Never want to add a change log entry for the ChangeLog buffer itself. | 78 | ;; Never want to add a change log entry for the ChangeLog file itself. |
| 79 | (if (equal file-name entry) | 79 | (if (equal entry "ChangeLog") |
| 80 | (setq entry nil | 80 | (setq entry nil |
| 81 | defun nil)) | 81 | defun nil)) |
| 82 | (if (and other-window (not (equal file-name buffer-file-name))) | 82 | (if (and other-window (not (equal file-name buffer-file-name))) |
| @@ -115,11 +115,16 @@ Third arg OTHER-WINDOW non-nil means visit in other window." | |||
| 115 | entry-boundary | 115 | entry-boundary |
| 116 | t) | 116 | t) |
| 117 | (1- (match-end 0))))))) | 117 | (1- (match-end 0))))))) |
| 118 | ;; Now insert the new line for this entry. | ||
| 118 | (cond (entry-position | 119 | (cond (entry-position |
| 119 | ;; Move to the existing entry for the same file. | 120 | ;; Move to the existing entry for the same file. |
| 120 | (goto-char entry-position) | 121 | (goto-char entry-position) |
| 121 | (re-search-forward "^\\s *$") | 122 | (re-search-forward "^\\s *$") |
| 122 | (open-line 1) | 123 | (beginning-of-line) |
| 124 | (while (looking-at "^\\s *$") | ||
| 125 | (delete-region (point) (save-excursion (forward-line 1) (point)))) | ||
| 126 | (insert "\n\n") | ||
| 127 | (forward-line -2) | ||
| 123 | (indent-relative-maybe)) | 128 | (indent-relative-maybe)) |
| 124 | (empty-entry | 129 | (empty-entry |
| 125 | ;; Put this file name into the existing empty entry. | 130 | ;; Put this file name into the existing empty entry. |
| @@ -131,14 +136,13 @@ Third arg OTHER-WINDOW non-nil means visit in other window." | |||
| 131 | (forward-line 1) | 136 | (forward-line 1) |
| 132 | (while (looking-at "\\sW") | 137 | (while (looking-at "\\sW") |
| 133 | (forward-line 1)) | 138 | (forward-line 1)) |
| 134 | (delete-region (point) | 139 | (while (looking-at "^\\s *$") |
| 135 | (progn | 140 | (delete-region (point) (save-excursion (forward-line 1) (point)))) |
| 136 | (skip-chars-backward "\n") | 141 | (insert "\n\n\n") |
| 137 | (point))) | 142 | (forward-line -2) |
| 138 | (open-line 3) | ||
| 139 | (forward-line 2) | ||
| 140 | (indent-to left-margin) | 143 | (indent-to left-margin) |
| 141 | (insert "* " (or entry "")))) | 144 | (insert "* " (or entry "")))) |
| 145 | ;; Now insert the function name, if we have one. | ||
| 142 | ;; Point is at the entry for this file, | 146 | ;; Point is at the entry for this file, |
| 143 | ;; either at the end of the line or at the first blank line. | 147 | ;; either at the end of the line or at the first blank line. |
| 144 | (if defun | 148 | (if defun |
| @@ -151,10 +155,11 @@ Third arg OTHER-WINDOW non-nil means visit in other window." | |||
| 151 | "" | 155 | "" |
| 152 | " ") | 156 | " ") |
| 153 | "(" defun "): ")) | 157 | "(" defun "): ")) |
| 158 | ;; No function name, so put in a colon unless we have just a star. | ||
| 154 | (if (not (save-excursion | 159 | (if (not (save-excursion |
| 155 | (beginning-of-line 1) | 160 | (beginning-of-line 1) |
| 156 | (looking-at "\\s *\\(\\*\\s *\\)?$"))) | 161 | (looking-at "\\s *\\(\\*\\s *\\)?$"))) |
| 157 | (insert ":"))))) | 162 | (insert ": "))))) |
| 158 | 163 | ||
| 159 | ;;;###autoload | 164 | ;;;###autoload |
| 160 | (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) | 165 | (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) |
| @@ -172,8 +177,7 @@ Interactively, with a prefix argument, the file name is prompted for." | |||
| 172 | 177 | ||
| 173 | (defun change-log-mode () | 178 | (defun change-log-mode () |
| 174 | "Major mode for editting change logs; like Indented Text Mode. | 179 | "Major mode for editting change logs; like Indented Text Mode. |
| 175 | Prevents numeric backups and sets `left-margin' to 8 and `fill-column' | 180 | Prevents numeric backups and sets `left-margin' to 8 and `fill-column'to 74. |
| 176 | to 74. | ||
| 177 | New log entries are usually made with \\[add-change-log-entry]." | 181 | New log entries are usually made with \\[add-change-log-entry]." |
| 178 | (interactive) | 182 | (interactive) |
| 179 | (kill-all-local-variables) | 183 | (kill-all-local-variables) |
| @@ -213,47 +217,65 @@ identifiers followed by `:' or `=', see variable | |||
| 213 | 217 | ||
| 214 | Has a preference of looking backwards." | 218 | Has a preference of looking backwards." |
| 215 | (save-excursion | 219 | (save-excursion |
| 216 | (cond ((memq major-mode '(emacs-lisp-mode lisp-mode)) | 220 | (let ((location (point))) |
| 217 | (beginning-of-defun) | 221 | (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode)) |
| 218 | (forward-word 1) | 222 | ;; If we are now precisely a the beginning of a defun, |
| 219 | (skip-chars-forward " ") | 223 | ;; make sure beginning-of-defun finds that one |
| 220 | (buffer-substring (point) | 224 | ;; rather than the previous one. |
| 221 | (progn (forward-sexp 1) (point)))) | 225 | (forward-char 1) |
| 222 | ((eq major-mode 'c-mode) | 226 | (beginning-of-defun) |
| 223 | ;; must be inside function body for this to work | 227 | ;; Make sure we are really inside the defun found, not after it. |
| 224 | (beginning-of-defun) | 228 | (if (save-excursion (end-of-defun) |
| 225 | (forward-line -1) | 229 | (< location (point))) |
| 226 | (while (looking-at "[ \t\n]") ; skip typedefs of arglist | 230 | (progn |
| 227 | (forward-line -1)) | 231 | (forward-word 1) |
| 228 | (down-list 1) ; into arglist | 232 | (skip-chars-forward " ") |
| 229 | (backward-up-list 1) | 233 | (buffer-substring (point) |
| 230 | (skip-chars-backward " \t") | 234 | (progn (forward-sexp 1) (point)))))) |
| 231 | (buffer-substring (point) | 235 | ((or (eq major-mode 'c-mode) |
| 232 | (progn (backward-sexp 1) | 236 | (eq major-mode 'c++-mode)) |
| 233 | (point)))) | 237 | ;; See if we are in the beginning part of a function, |
| 234 | ((memq major-mode | 238 | ;; before the open brace. If so, advance forward. |
| 235 | '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el | 239 | (while (not (or (looking-at "{") |
| 236 | plain-tex-mode latex-mode;; cmutex.el | 240 | (looking-at "\\s *$"))) |
| 237 | )) | 241 | (forward-line 1)) |
| 238 | (if (re-search-backward | 242 | (forward-char 1) |
| 239 | "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) | 243 | (beginning-of-defun) |
| 240 | (progn | 244 | (if (save-excursion (end-of-defun) |
| 241 | (goto-char (match-beginning 0)) | 245 | (< location (point))) |
| 242 | (buffer-substring (1+ (point));; without initial backslash | 246 | (progn |
| 243 | (progn | 247 | (forward-line -1) |
| 244 | (end-of-line) | 248 | (while (looking-at "[ \t\n]") ; skip typedefs of arglist |
| 245 | (point)))))) | 249 | (forward-line -1)) |
| 246 | ((eq major-mode 'texinfo-mode) | 250 | (down-list 1) ; into arglist |
| 247 | (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) | 251 | (backward-up-list 1) |
| 248 | (buffer-substring (match-beginning 1) | 252 | (skip-chars-backward " \t") |
| 249 | (match-end 1)))) | 253 | (buffer-substring (point) |
| 250 | (t | 254 | (progn (backward-sexp 1) |
| 251 | ;; If all else fails, try heuristics | 255 | (point)))))) |
| 252 | (let (case-fold-search) | 256 | ((memq major-mode |
| 253 | (if (re-search-backward add-log-current-defun-header-regexp | 257 | '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el |
| 254 | (- (point) 10000) | 258 | plain-tex-mode latex-mode;; cmutex.el |
| 255 | t) | 259 | )) |
| 260 | (if (re-search-backward | ||
| 261 | "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) | ||
| 262 | (progn | ||
| 263 | (goto-char (match-beginning 0)) | ||
| 264 | (buffer-substring (1+ (point));; without initial backslash | ||
| 265 | (progn | ||
| 266 | (end-of-line) | ||
| 267 | (point)))))) | ||
| 268 | ((eq major-mode 'texinfo-mode) | ||
| 269 | (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) | ||
| 256 | (buffer-substring (match-beginning 1) | 270 | (buffer-substring (match-beginning 1) |
| 257 | (match-end 1)))))))) | 271 | (match-end 1)))) |
| 272 | (t | ||
| 273 | ;; If all else fails, try heuristics | ||
| 274 | (let (case-fold-search) | ||
| 275 | (if (re-search-backward add-log-current-defun-header-regexp | ||
| 276 | (- (point) 10000) | ||
| 277 | t) | ||
| 278 | (buffer-substring (match-beginning 1) | ||
| 279 | (match-end 1))))))))) | ||
| 258 | 280 | ||
| 259 | ;;; add-log.el ends here | 281 | ;;; add-log.el ends here |
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el index 46ffe0647f6..99f0e31cdfc 100644 --- a/lisp/progmodes/c-mode.el +++ b/lisp/progmodes/c-mode.el | |||
| @@ -130,42 +130,6 @@ If you do not want a leading newline before braces then use: | |||
| 130 | "*Non-nil means TAB in C mode should always reindent the current line, | 130 | "*Non-nil means TAB in C mode should always reindent the current line, |
| 131 | regardless of where in the line point is when the TAB command is used.") | 131 | regardless of where in the line point is when the TAB command is used.") |
| 132 | 132 | ||
| 133 | (defun set-c-style (&optional style) | ||
| 134 | "Set up the c-mode style variables from the c-style variable or if | ||
| 135 | STYLE argument is given, use that. It makes the c indentation style | ||
| 136 | variables buffer local." | ||
| 137 | (interactive) | ||
| 138 | (let ((c-styles (mapcar 'car c-style-alist))) | ||
| 139 | (if (interactive-p) | ||
| 140 | (setq style | ||
| 141 | (let ((style-string ; get style name with completion | ||
| 142 | (completing-read | ||
| 143 | (format "Set c mode indentation style to (default %s): " | ||
| 144 | default-c-style) | ||
| 145 | (vconcat c-styles) | ||
| 146 | (function (lambda (arg) (memq arg c-styles))) | ||
| 147 | ))) | ||
| 148 | (if (string-equal "" style-string) | ||
| 149 | default-c-style | ||
| 150 | (intern style-string)) | ||
| 151 | ))) | ||
| 152 | (setq style (or style c-style)) ; use c-style if style is nil | ||
| 153 | (make-local-variable 'c-style) | ||
| 154 | (if (memq style c-styles) | ||
| 155 | (setq c-style style) | ||
| 156 | (error "Bad c style: %s" style) | ||
| 157 | ) | ||
| 158 | (message "c-style: %s" c-style) | ||
| 159 | ; finally, set the indentation style variables making each one local | ||
| 160 | (mapcar (function (lambda (c-style-pair) | ||
| 161 | (make-local-variable (car c-style-pair)) | ||
| 162 | (set (car c-style-pair) | ||
| 163 | (cdr c-style-pair)))) | ||
| 164 | (cdr (assq c-style c-style-alist))) | ||
| 165 | c-style | ||
| 166 | ) | ||
| 167 | ) | ||
| 168 | |||
| 169 | (defun c-mode () | 133 | (defun c-mode () |
| 170 | "Major mode for editing C code. | 134 | "Major mode for editing C code. |
| 171 | Expression and list commands understand all C brackets. | 135 | Expression and list commands understand all C brackets. |
| @@ -1066,18 +1030,90 @@ ENDPOS is encountered." | |||
| 1066 | (indent-c-exp endmark) | 1030 | (indent-c-exp endmark) |
| 1067 | (set-marker endmark nil)))) | 1031 | (set-marker endmark nil)))) |
| 1068 | 1032 | ||
| 1069 | (defun set-c-style (style) | 1033 | (defun set-c-style (style &optional global) |
| 1070 | "Set C-mode variables to use one of several different indentation styles. | 1034 | "Set C-mode variables to use one of several different indentation styles. |
| 1071 | Takes one argument, a string representing the desired style. | 1035 | The arguments are a string representing the desired style |
| 1072 | Available styles are GNU, K&R, BSD and Whitesmith." | 1036 | and a flag which, if non-nil, means to set the style globally. |
| 1037 | \(Interactively, the flag comes from the prefix argument.) | ||
| 1038 | Available styles are GNU, K&R, BSD and Whitesmith. | ||
| 1073 | (interactive (list (completing-read "Use which C indentation style? " | 1039 | (interactive (list (completing-read "Use which C indentation style? " |
| 1074 | c-style-alist nil t))) | 1040 | c-style-alist nil t) |
| 1041 | current-prefix-arg)) | ||
| 1075 | (let ((vars (cdr (assoc style c-style-alist)))) | 1042 | (let ((vars (cdr (assoc style c-style-alist)))) |
| 1076 | (if vars | 1043 | (or vars |
| 1077 | (if (interactive-p) (message "Using %s C indentation style" style)) | 1044 | (error "Invalid C indentation style `%s'" style)) |
| 1078 | (error "Bogus style type, \"%s\"" style)) | ||
| 1079 | (while vars | 1045 | (while vars |
| 1046 | (or global | ||
| 1047 | (make-local-variable (car (car vars)))) | ||
| 1080 | (set (car (car vars)) (cdr (car vars))) | 1048 | (set (car (car vars)) (cdr (car vars))) |
| 1081 | (setq vars (cdr vars))))) | 1049 | (setq vars (cdr vars))))) |
| 1050 | |||
| 1051 | ;;; This page handles insertion and removal of backslashes for C macros. | ||
| 1052 | |||
| 1053 | (defvar c-backslash-column 48 | ||
| 1054 | "*Minimum column for end-of-line backslashes of macro definitions.") | ||
| 1055 | |||
| 1056 | (defun c-backslash-region (from to delete-flag) | ||
| 1057 | "Insert, align, or delete end-of-line backslashes on the lines in the region. | ||
| 1058 | With no argument, inserts backslashes and aligns existing backslashes. | ||
| 1059 | With an argument, deletes the backslashes. | ||
| 1060 | |||
| 1061 | This function does not modify the last line of the region if the region ends | ||
| 1062 | right at the start of the following line; it does not modify blank lines | ||
| 1063 | at the start of the region. So you can put the region around an entire macro | ||
| 1064 | definition and conveniently use this command." | ||
| 1065 | (interactive "r\nP") | ||
| 1066 | (save-excursion | ||
| 1067 | (goto-char from) | ||
| 1068 | (let ((column c-backslash-column) | ||
| 1069 | (endmark (make-marker))) | ||
| 1070 | (move-marker endmark to) | ||
| 1071 | ;; Compute the smallest column number past the ends of all the lines. | ||
| 1072 | (if (not delete-flag) | ||
| 1073 | (while (< (point) to) | ||
| 1074 | (end-of-line) | ||
| 1075 | (if (= (preceding-char) ?\\) | ||
| 1076 | (progn (forward-char -1) | ||
| 1077 | (skip-chars-backward " \t"))) | ||
| 1078 | (setq column (max column (1+ (current-column)))) | ||
| 1079 | (forward-line 1))) | ||
| 1080 | ;; Adjust upward to a tab column, if that doesn't push past the margin. | ||
| 1081 | (if (> (% column tab-width) 0) | ||
| 1082 | (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width))) | ||
| 1083 | (if (< adjusted (window-width)) | ||
| 1084 | (setq column adjusted)))) | ||
| 1085 | ;; Don't modify blank lines at start of region. | ||
| 1086 | (goto-char from) | ||
| 1087 | (while (and (< (point) endmark) (eolp)) | ||
| 1088 | (forward-line 1)) | ||
| 1089 | ;; Add or remove backslashes on all the lines. | ||
| 1090 | (while (and (< (point) endmark) | ||
| 1091 | ;; Don't backslashify the last line | ||
| 1092 | ;; if the region ends right at the start of the next line. | ||
| 1093 | (save-excursion | ||
| 1094 | (forward-line 1) | ||
| 1095 | (< (point) endmark))) | ||
| 1096 | (if (not delete-flag) | ||
| 1097 | (c-append-backslash column) | ||
| 1098 | (c-delete-backslash)) | ||
| 1099 | (forward-line 1)) | ||
| 1100 | (move-marker endmark nil)))) | ||
| 1101 | |||
| 1102 | (defun c-append-backslash (column) | ||
| 1103 | (end-of-line) | ||
| 1104 | ;; Note that "\\\\" is needed to get one backslash. | ||
| 1105 | (if (= (preceding-char) ?\\) | ||
| 1106 | (progn (forward-char -1) | ||
| 1107 | (delete-horizontal-space) | ||
| 1108 | (indent-to column)) | ||
| 1109 | (indent-to column) | ||
| 1110 | (insert "\\"))) | ||
| 1111 | |||
| 1112 | (defun c-delete-backslash () | ||
| 1113 | (end-of-line) | ||
| 1114 | (forward-char -1) | ||
| 1115 | (if (looking-at "\\\\") | ||
| 1116 | (delete-region (1+ (point)) | ||
| 1117 | (progn (skip-chars-backward " \t") (point))))) | ||
| 1082 | 1118 | ||
| 1083 | ;;; c-mode.el ends here | 1119 | ;;; c-mode.el ends here |