diff options
| author | Martin Rudalics | 2008-08-07 09:29:58 +0000 |
|---|---|---|
| committer | Martin Rudalics | 2008-08-07 09:29:58 +0000 |
| commit | bc53d5446c3526d9abad0f4b3d319f2c9adb772d (patch) | |
| tree | 79a9177e0af060001a78fd9d51bf3a743e16a668 | |
| parent | 6b8bc48996dc00ed400558fea083b08b4c679fbe (diff) | |
| download | emacs-bc53d5446c3526d9abad0f4b3d319f2c9adb772d.tar.gz emacs-bc53d5446c3526d9abad0f4b3d319f2c9adb772d.zip | |
(change-log-search-tag-name)
(change-log-goto-source): Fix behavior when point is not on tag.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/add-log.el | 107 |
2 files changed, 64 insertions, 48 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8727b6d9a34..bcfeb56b29b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2008-08-07 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * add-log.el (change-log-search-tag-name) | ||
| 4 | (change-log-goto-source): Fix behavior when point is not on tag. | ||
| 5 | |||
| 1 | 2008-08-06 Adrian Robert <Adrian.B.Robert@gmail.com> | 6 | 2008-08-06 Adrian Robert <Adrian.B.Robert@gmail.com> |
| 2 | 7 | ||
| 3 | * startup.el (command-line-ns-option-alist): Use ignore instead of | 8 | * startup.el (command-line-ns-option-alist): Use ignore instead of |
diff --git a/lisp/add-log.el b/lisp/add-log.el index 1acc064beff..b7d855b7c62 100644 --- a/lisp/add-log.el +++ b/lisp/add-log.el | |||
| @@ -365,14 +365,14 @@ the tag and whose cdr is the position where the tag was found." | |||
| 365 | (change-log-search-tag-name-1 at))) | 365 | (change-log-search-tag-name-1 at))) |
| 366 | (error nil)) | 366 | (error nil)) |
| 367 | (condition-case nil | 367 | (condition-case nil |
| 368 | ;; Before parenthesized list? | 368 | ;; Before parenthesized list on same line? |
| 369 | (save-excursion | 369 | (save-excursion |
| 370 | (when (and (skip-chars-forward " \t") | 370 | (when (and (skip-chars-forward " \t") |
| 371 | (looking-at change-log-tag-re)) | 371 | (looking-at change-log-tag-re)) |
| 372 | (change-log-search-tag-name-1))) | 372 | (change-log-search-tag-name-1))) |
| 373 | (error nil)) | 373 | (error nil)) |
| 374 | (condition-case nil | 374 | (condition-case nil |
| 375 | ;; Near filename? | 375 | ;; Near file name? |
| 376 | (save-excursion | 376 | (save-excursion |
| 377 | (when (and (progn | 377 | (when (and (progn |
| 378 | (beginning-of-line) | 378 | (beginning-of-line) |
| @@ -383,40 +383,32 @@ the tag and whose cdr is the position where the tag was found." | |||
| 383 | (change-log-search-tag-name-1))) | 383 | (change-log-search-tag-name-1))) |
| 384 | (error nil)) | 384 | (error nil)) |
| 385 | (condition-case nil | 385 | (condition-case nil |
| 386 | ;; Before filename? | 386 | ;; Anywhere else within current entry? |
| 387 | (save-excursion | 387 | (let ((from |
| 388 | (when (and (progn | 388 | (save-excursion |
| 389 | (skip-syntax-backward " ") | 389 | (end-of-line) |
| 390 | (beginning-of-line) | 390 | (if (re-search-backward change-log-start-entry-re nil t) |
| 391 | (looking-at change-log-file-names-re)) | 391 | (match-beginning 0) |
| 392 | (goto-char (match-end 0)) | 392 | (point-min)))) |
| 393 | (skip-syntax-forward " ") | 393 | (to |
| 394 | (looking-at change-log-tag-re)) | 394 | (save-excursion |
| 395 | (change-log-search-tag-name-1))) | 395 | (end-of-line) |
| 396 | (error nil)) | 396 | (if (re-search-forward change-log-start-entry-re nil t) |
| 397 | (condition-case nil | 397 | (match-beginning 0) |
| 398 | ;; Near start entry? | 398 | (point-max))))) |
| 399 | (save-excursion | 399 | (when (and (< from to) (<= from at) (<= at to)) |
| 400 | (when (and (progn | 400 | (save-restriction |
| 401 | (beginning-of-line) | 401 | ;; Narrow to current change log entry. |
| 402 | (looking-at change-log-start-entry-re)) | 402 | (narrow-to-region from to) |
| 403 | (forward-line) ; Won't work for multiple | 403 | (cond |
| 404 | ; names, etc. | 404 | ((re-search-backward change-log-tag-re nil t) |
| 405 | (skip-syntax-forward " ") | 405 | (narrow-to-region (match-beginning 1) (match-end 1)) |
| 406 | (progn | 406 | (goto-char (point-max)) |
| 407 | (beginning-of-line) | 407 | (cons (find-tag-default) (point-max))) |
| 408 | (looking-at change-log-file-names-re)) | 408 | ((re-search-forward change-log-tag-re nil t) |
| 409 | (goto-char (match-end 0)) | 409 | (narrow-to-region (match-beginning 1) (match-end 1)) |
| 410 | (re-search-forward change-log-tag-re)) | 410 | (goto-char (point-min)) |
| 411 | (change-log-search-tag-name-1))) | 411 | (cons (find-tag-default) (point-min))))))) |
| 412 | (error nil)) | ||
| 413 | (condition-case nil | ||
| 414 | ;; After parenthesized list?. | ||
| 415 | (when (re-search-backward change-log-tag-re) | ||
| 416 | (save-restriction | ||
| 417 | (narrow-to-region (match-beginning 1) (match-end 1)) | ||
| 418 | (goto-char (point-max)) | ||
| 419 | (cons (find-tag-default) (point-max)))) | ||
| 420 | (error nil)))))) | 412 | (error nil)))))) |
| 421 | 413 | ||
| 422 | (defvar change-log-find-head nil) | 414 | (defvar change-log-find-head nil) |
| @@ -481,9 +473,10 @@ BUFFER denoting the last match for TAG in the last search." | |||
| 481 | nil))) | 473 | nil))) |
| 482 | 474 | ||
| 483 | (defun change-log-goto-source () | 475 | (defun change-log-goto-source () |
| 484 | "Go to source location of change log tag near `point'. | 476 | "Go to source location of \"change log tag\" near `point'. |
| 485 | A change log tag is a symbol within a parenthesized, | 477 | A change log tag is a symbol within a parenthesized, |
| 486 | comma-separated list." | 478 | comma-separated list. If no suitable tag can be found nearby, |
| 479 | try to visit the file for the change under `point' instead." | ||
| 487 | (interactive) | 480 | (interactive) |
| 488 | (if (and (eq last-command 'change-log-goto-source) | 481 | (if (and (eq last-command 'change-log-goto-source) |
| 489 | change-log-find-tail) | 482 | change-log-find-tail) |
| @@ -496,20 +489,38 @@ comma-separated list." | |||
| 496 | (car change-log-find-head) | 489 | (car change-log-find-head) |
| 497 | (nth 2 change-log-find-head))))) | 490 | (nth 2 change-log-find-head))))) |
| 498 | (save-excursion | 491 | (save-excursion |
| 499 | (let* ((tag-at (change-log-search-tag-name)) | 492 | (let* ((at (point)) |
| 493 | (tag-at (change-log-search-tag-name)) | ||
| 500 | (tag (car tag-at)) | 494 | (tag (car tag-at)) |
| 501 | (file (when tag-at | 495 | (file (when tag-at (change-log-search-file-name (cdr tag-at)))) |
| 502 | (change-log-search-file-name (cdr tag-at))))) | 496 | (file-at (when file (match-beginning 2))) |
| 503 | (if (or (not tag) (not file)) | 497 | ;; `file-2' is the file `change-log-search-file-name' finds |
| 504 | (error "No suitable tag near `point'") | 498 | ;; at `point'. We use `file-2' as a fallback when `tag' or |
| 499 | ;; `file' are not suitable for some reason. | ||
| 500 | (file-2 (change-log-search-file-name at)) | ||
| 501 | (file-2-at (when file-2 (match-beginning 2)))) | ||
| 502 | (cond | ||
| 503 | ((and (or (not tag) (not file) (not (file-exists-p file))) | ||
| 504 | (or (not file-2) (not (file-exists-p file-2)))) | ||
| 505 | (error "Cannot find tag or file near `point'")) | ||
| 506 | ((and file-2 (file-exists-p file-2) | ||
| 507 | (or (not tag) (not file) (not (file-exists-p file)) | ||
| 508 | (and (or (and (< file-at file-2-at) (<= file-2-at at)) | ||
| 509 | (and (<= at file-2-at) (< file-2-at file-at)))))) | ||
| 510 | ;; We either have not found a suitable file name or `file-2' | ||
| 511 | ;; provides a "better" file name wrt `point'. Go to the | ||
| 512 | ;; buffer of `file-2' instead. | ||
| 513 | (display-buffer (find-file-noselect file-2))) | ||
| 514 | (t | ||
| 505 | (setq change-log-find-head | 515 | (setq change-log-find-head |
| 506 | (list tag (concat "\\_<" (regexp-quote tag) "\\_>") | 516 | (list tag (concat "\\_<" (regexp-quote tag) "\\_>") |
| 507 | file (find-file-noselect file))) | 517 | file (find-file-noselect file))) |
| 508 | (condition-case nil | 518 | (condition-case nil |
| 509 | (setq change-log-find-tail | 519 | (setq change-log-find-tail |
| 510 | (apply 'change-log-goto-source-1 change-log-find-head)) | 520 | (apply 'change-log-goto-source-1 change-log-find-head)) |
| 511 | (error (format "Cannot find matches for tag `%s' in `%s'" | 521 | (error |
| 512 | tag file)))))))) | 522 | (format "Cannot find matches for tag `%s' in file `%s'" |
| 523 | tag file))))))))) | ||
| 513 | 524 | ||
| 514 | (defun change-log-next-error (&optional argp reset) | 525 | (defun change-log-next-error (&optional argp reset) |
| 515 | "Move to the Nth (default 1) next match in an Occur mode buffer. | 526 | "Move to the Nth (default 1) next match in an Occur mode buffer. |
| @@ -520,15 +531,15 @@ Compatibility function for \\[next-error] invocations." | |||
| 520 | (down (< argp 0)) ; are we going down? (is argp negative?) | 531 | (down (< argp 0)) ; are we going down? (is argp negative?) |
| 521 | (up (not down)) | 532 | (up (not down)) |
| 522 | (search-function (if up 're-search-forward 're-search-backward))) | 533 | (search-function (if up 're-search-forward 're-search-backward))) |
| 523 | 534 | ||
| 524 | ;; set the starting position | 535 | ;; set the starting position |
| 525 | (goto-char (cond (reset (point-min)) | 536 | (goto-char (cond (reset (point-min)) |
| 526 | (down (line-beginning-position)) | 537 | (down (line-beginning-position)) |
| 527 | (up (line-end-position)) | 538 | (up (line-end-position)) |
| 528 | ((point)))) | 539 | ((point)))) |
| 529 | 540 | ||
| 530 | (funcall search-function change-log-file-names-re nil t count)) | 541 | (funcall search-function change-log-file-names-re nil t count)) |
| 531 | 542 | ||
| 532 | (beginning-of-line) | 543 | (beginning-of-line) |
| 533 | ;; if we found a place to visit... | 544 | ;; if we found a place to visit... |
| 534 | (when (looking-at change-log-file-names-re) | 545 | (when (looking-at change-log-file-names-re) |