diff options
| author | Richard M. Stallman | 1992-10-19 22:39:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-10-19 22:39:55 +0000 |
| commit | 2cc0b7656d66e875248667e1a3ffc0262108d7a5 (patch) | |
| tree | e294ad5b6984a01422312fb6c440fb1218ab0ee7 | |
| parent | 81d478f3c6c08480a20dd9caab5d5824cc9bcf17 (diff) | |
| download | emacs-2cc0b7656d66e875248667e1a3ffc0262108d7a5.tar.gz emacs-2cc0b7656d66e875248667e1a3ffc0262108d7a5.zip | |
(add-log-current-defun): Add condition-case around
the body, so at worst we return nil.
| -rw-r--r-- | lisp/add-log.el | 257 |
1 files changed, 129 insertions, 128 deletions
diff --git a/lisp/add-log.el b/lisp/add-log.el index f7f61b3952f..780c2d84cf8 100644 --- a/lisp/add-log.el +++ b/lisp/add-log.el | |||
| @@ -218,136 +218,137 @@ identifiers followed by `:' or `=', see variable | |||
| 218 | `add-log-current-defun-header-regexp'. | 218 | `add-log-current-defun-header-regexp'. |
| 219 | 219 | ||
| 220 | Has a preference of looking backwards." | 220 | Has a preference of looking backwards." |
| 221 | (save-excursion | 221 | (condition-case nil |
| 222 | (let ((location (point))) | 222 | (save-excursion |
| 223 | (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode)) | 223 | (let ((location (point))) |
| 224 | ;; If we are now precisely a the beginning of a defun, | 224 | (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode)) |
| 225 | ;; make sure beginning-of-defun finds that one | 225 | ;; If we are now precisely a the beginning of a defun, |
| 226 | ;; rather than the previous one. | 226 | ;; make sure beginning-of-defun finds that one |
| 227 | (or (eobp) (forward-char 1)) | 227 | ;; rather than the previous one. |
| 228 | (beginning-of-defun) | 228 | (or (eobp) (forward-char 1)) |
| 229 | ;; Make sure we are really inside the defun found, not after it. | 229 | (beginning-of-defun) |
| 230 | (if (and (progn (end-of-defun) | 230 | ;; Make sure we are really inside the defun found, not after it. |
| 231 | (< location (point))) | 231 | (if (and (progn (end-of-defun) |
| 232 | (progn (forward-sexp -1) | 232 | (< location (point))) |
| 233 | (>= location (point)))) | 233 | (progn (forward-sexp -1) |
| 234 | (progn | 234 | (>= location (point)))) |
| 235 | (forward-word 1) | 235 | (progn |
| 236 | (skip-chars-forward " ") | 236 | (forward-word 1) |
| 237 | (buffer-substring (point) | 237 | (skip-chars-forward " ") |
| 238 | (progn (forward-sexp 1) (point)))))) | 238 | (buffer-substring (point) |
| 239 | ((and (memq major-mode '(c-mode 'c++-mode)) | 239 | (progn (forward-sexp 1) (point)))))) |
| 240 | (save-excursion (beginning-of-line) | 240 | ((and (memq major-mode '(c-mode 'c++-mode)) |
| 241 | ;; Use eq instead of = here to avoid | 241 | (save-excursion (beginning-of-line) |
| 242 | ;; error when at bob and char-after | 242 | ;; Use eq instead of = here to avoid |
| 243 | ;; returns nil. | 243 | ;; error when at bob and char-after |
| 244 | (while (eq (char-after (- (point) 2)) ?\\) | 244 | ;; returns nil. |
| 245 | (forward-line -1)) | 245 | (while (eq (char-after (- (point) 2)) ?\\) |
| 246 | (looking-at "[ \t]*#[ \t]*define[ \t]"))) | ||
| 247 | ;; Handle a C macro definition. | ||
| 248 | (beginning-of-line) | ||
| 249 | (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above | ||
| 250 | (forward-line -1)) | ||
| 251 | (search-forward "define") | ||
| 252 | (skip-chars-forward " \t") | ||
| 253 | (buffer-substring (point) | ||
| 254 | (progn (forward-sexp 1) (point)))) | ||
| 255 | ((memq major-mode '(c-mode 'c++-mode)) | ||
| 256 | (beginning-of-line) | ||
| 257 | ;; See if we are in the beginning part of a function, | ||
| 258 | ;; before the open brace. If so, advance forward. | ||
| 259 | (while (not (looking-at "{\\|\\(\\s *$\\)")) | ||
| 260 | (forward-line 1)) | ||
| 261 | (or (eobp) | ||
| 262 | (forward-char 1)) | ||
| 263 | (beginning-of-defun) | ||
| 264 | (if (progn (end-of-defun) | ||
| 265 | (< location (point))) | ||
| 266 | (progn | ||
| 267 | (backward-sexp 1) | ||
| 268 | (let (beg tem) | ||
| 269 | |||
| 270 | (forward-line -1) | ||
| 271 | ;; Skip back over typedefs of arglist. | ||
| 272 | (while (and (not (bobp)) | ||
| 273 | (looking-at "[ \t\n]")) | ||
| 274 | (forward-line -1)) | ||
| 275 | ;; See if this is using the DEFUN macro used in Emacs, | ||
| 276 | ;; or the DEFUN macro used by the C library. | ||
| 277 | (if (condition-case nil | ||
| 278 | (and (save-excursion | ||
| 279 | (forward-line 1) | ||
| 280 | (backward-sexp 1) | ||
| 281 | (beginning-of-line) | ||
| 282 | (setq tem (point)) | ||
| 283 | (looking-at "DEFUN\\b")) | ||
| 284 | (>= location tem)) | ||
| 285 | (error nil)) | ||
| 286 | (progn | ||
| 287 | (goto-char tem) | ||
| 288 | (down-list 1) | ||
| 289 | (if (= (char-after (point)) ?\") | ||
| 290 | (progn | ||
| 291 | (forward-sexp 1) | ||
| 292 | (skip-chars-forward " ,"))) | ||
| 293 | (buffer-substring (point) | ||
| 294 | (progn (forward-sexp 1) (point)))) | ||
| 295 | ;; Ordinary C function syntax. | ||
| 296 | (setq beg (point)) | ||
| 297 | (if (condition-case nil | ||
| 298 | ;; Protect against "Unbalanced parens" error. | ||
| 299 | (progn | ||
| 300 | (down-list 1) ; into arglist | ||
| 301 | (backward-up-list 1) | ||
| 302 | (skip-chars-backward " \t") | ||
| 303 | t) | ||
| 304 | (error nil)) | ||
| 305 | ;; Verify initial pos was after | ||
| 306 | ;; real start of function. | ||
| 307 | (if (and (save-excursion | ||
| 308 | (goto-char beg) | ||
| 309 | ;; For this purpose, include the line | ||
| 310 | ;; that has the decl keywords. This | ||
| 311 | ;; may also include some of the | ||
| 312 | ;; comments before the function. | ||
| 313 | (while (and (not (bobp)) | ||
| 314 | (save-excursion | ||
| 315 | (forward-line -1) | ||
| 316 | (looking-at "[^\n\f]"))) | ||
| 317 | (forward-line -1)) | 246 | (forward-line -1)) |
| 318 | (>= location (point))) | 247 | (looking-at "[ \t]*#[ \t]*define[ \t]"))) |
| 319 | ;; Consistency check: going down and up | 248 | ;; Handle a C macro definition. |
| 320 | ;; shouldn't take us back before BEG. | 249 | (beginning-of-line) |
| 321 | (> (point) beg)) | 250 | (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above |
| 322 | (buffer-substring (point) | 251 | (forward-line -1)) |
| 323 | (progn (backward-sexp 1) | 252 | (search-forward "define") |
| 324 | (point)))))))))) | 253 | (skip-chars-forward " \t") |
| 325 | ((memq major-mode | 254 | (buffer-substring (point) |
| 326 | '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el | 255 | (progn (forward-sexp 1) (point)))) |
| 327 | plain-tex-mode latex-mode;; cmutex.el | 256 | ((memq major-mode '(c-mode 'c++-mode)) |
| 328 | )) | 257 | (beginning-of-line) |
| 329 | (if (re-search-backward | 258 | ;; See if we are in the beginning part of a function, |
| 330 | "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) | 259 | ;; before the open brace. If so, advance forward. |
| 331 | (progn | 260 | (while (not (looking-at "{\\|\\(\\s *$\\)")) |
| 332 | (goto-char (match-beginning 0)) | 261 | (forward-line 1)) |
| 333 | (buffer-substring (1+ (point));; without initial backslash | 262 | (or (eobp) |
| 334 | (progn | 263 | (forward-char 1)) |
| 335 | (end-of-line) | 264 | (beginning-of-defun) |
| 336 | (point)))))) | 265 | (if (progn (end-of-defun) |
| 337 | ((eq major-mode 'texinfo-mode) | 266 | (< location (point))) |
| 338 | (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) | 267 | (progn |
| 339 | (buffer-substring (match-beginning 1) | 268 | (backward-sexp 1) |
| 340 | (match-end 1)))) | 269 | (let (beg tem) |
| 341 | (t | ||
| 342 | ;; If all else fails, try heuristics | ||
| 343 | (let (case-fold-search) | ||
| 344 | (end-of-line) | ||
| 345 | (if (re-search-backward add-log-current-defun-header-regexp | ||
| 346 | (- (point) 10000) | ||
| 347 | t) | ||
| 348 | (buffer-substring (match-beginning 1) | ||
| 349 | (match-end 1))))))))) | ||
| 350 | 270 | ||
| 271 | (forward-line -1) | ||
| 272 | ;; Skip back over typedefs of arglist. | ||
| 273 | (while (and (not (bobp)) | ||
| 274 | (looking-at "[ \t\n]")) | ||
| 275 | (forward-line -1)) | ||
| 276 | ;; See if this is using the DEFUN macro used in Emacs, | ||
| 277 | ;; or the DEFUN macro used by the C library. | ||
| 278 | (if (condition-case nil | ||
| 279 | (and (save-excursion | ||
| 280 | (forward-line 1) | ||
| 281 | (backward-sexp 1) | ||
| 282 | (beginning-of-line) | ||
| 283 | (setq tem (point)) | ||
| 284 | (looking-at "DEFUN\\b")) | ||
| 285 | (>= location tem)) | ||
| 286 | (error nil)) | ||
| 287 | (progn | ||
| 288 | (goto-char tem) | ||
| 289 | (down-list 1) | ||
| 290 | (if (= (char-after (point)) ?\") | ||
| 291 | (progn | ||
| 292 | (forward-sexp 1) | ||
| 293 | (skip-chars-forward " ,"))) | ||
| 294 | (buffer-substring (point) | ||
| 295 | (progn (forward-sexp 1) (point)))) | ||
| 296 | ;; Ordinary C function syntax. | ||
| 297 | (setq beg (point)) | ||
| 298 | (if (condition-case nil | ||
| 299 | ;; Protect against "Unbalanced parens" error. | ||
| 300 | (progn | ||
| 301 | (down-list 1) ; into arglist | ||
| 302 | (backward-up-list 1) | ||
| 303 | (skip-chars-backward " \t") | ||
| 304 | t) | ||
| 305 | (error nil)) | ||
| 306 | ;; Verify initial pos was after | ||
| 307 | ;; real start of function. | ||
| 308 | (if (and (save-excursion | ||
| 309 | (goto-char beg) | ||
| 310 | ;; For this purpose, include the line | ||
| 311 | ;; that has the decl keywords. This | ||
| 312 | ;; may also include some of the | ||
| 313 | ;; comments before the function. | ||
| 314 | (while (and (not (bobp)) | ||
| 315 | (save-excursion | ||
| 316 | (forward-line -1) | ||
| 317 | (looking-at "[^\n\f]"))) | ||
| 318 | (forward-line -1)) | ||
| 319 | (>= location (point))) | ||
| 320 | ;; Consistency check: going down and up | ||
| 321 | ;; shouldn't take us back before BEG. | ||
| 322 | (> (point) beg)) | ||
| 323 | (buffer-substring (point) | ||
| 324 | (progn (backward-sexp 1) | ||
| 325 | (point)))))))))) | ||
| 326 | ((memq major-mode | ||
| 327 | '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el | ||
| 328 | plain-tex-mode latex-mode;; cmutex.el | ||
| 329 | )) | ||
| 330 | (if (re-search-backward | ||
| 331 | "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t) | ||
| 332 | (progn | ||
| 333 | (goto-char (match-beginning 0)) | ||
| 334 | (buffer-substring (1+ (point));; without initial backslash | ||
| 335 | (progn | ||
| 336 | (end-of-line) | ||
| 337 | (point)))))) | ||
| 338 | ((eq major-mode 'texinfo-mode) | ||
| 339 | (if (re-search-backward "^@node[ \t]+\\([^,]+\\)," nil t) | ||
| 340 | (buffer-substring (match-beginning 1) | ||
| 341 | (match-end 1)))) | ||
| 342 | (t | ||
| 343 | ;; If all else fails, try heuristics | ||
| 344 | (let (case-fold-search) | ||
| 345 | (end-of-line) | ||
| 346 | (if (re-search-backward add-log-current-defun-header-regexp | ||
| 347 | (- (point) 10000) | ||
| 348 | t) | ||
| 349 | (buffer-substring (match-beginning 1) | ||
| 350 | (match-end 1)))))))) | ||
| 351 | (error nil))) | ||
| 351 | 352 | ||
| 352 | 353 | ||
| 353 | (provide 'add-log) | 354 | (provide 'add-log) |