Mercurial > emacs
comparison lisp/bookmark.el @ 91327:606f2d163a64
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-312
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 09 Jan 2008 01:21:15 +0000 |
parents | 56a72e2bd635 0c4a74c24677 |
children |
comparison
equal
deleted
inserted
replaced
91326:b1a63d7fa09c | 91327:606f2d163a64 |
---|---|
1 ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later | 1 ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later |
2 | 2 |
3 ;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003, | 3 ;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003, |
4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc. | 4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Karl Fogel <kfogel@red-bean.com> | 6 ;; Author: Karl Fogel <kfogel@red-bean.com> |
7 ;; Maintainer: Karl Fogel <kfogel@red-bean.com> | 7 ;; Maintainer: Karl Fogel <kfogel@red-bean.com> |
8 ;; Created: July, 1993 | 8 ;; Created: July, 1993 |
9 ;; Keywords: bookmarks, placeholders, annotations | 9 ;; Keywords: bookmarks, placeholders, annotations |
489 | 489 |
490 The function will be called with two arguments: ANNOTATION and | 490 The function will be called with two arguments: ANNOTATION and |
491 INFO-NODE. See `bookmark-make-cell-for-text-file' for a | 491 INFO-NODE. See `bookmark-make-cell-for-text-file' for a |
492 description. | 492 description. |
493 | 493 |
494 The returned record may contain a special cons (handler | 494 The returned record may contain a special cons (handler . SOME-FUNCTION) |
495 . some-function) which sets the handler function that should be | 495 which sets the handler function that should be used to open this |
496 used to open this bookmark instead of `bookmark-jump-noselect'. | 496 bookmark instead of `bookmark-jump-noselect'. The handler should |
497 It should return a cons (BUFFER . POINT) indicating buffer | 497 return an alist like the one that function returns, and (of course) |
498 showing the bookmarked location and the value of point in that | 498 should likewise not select the buffer.") |
499 buffer. Like `bookmark-jump-noselect' the buffer shouldn't be | |
500 selected by the handler.") | |
501 | 499 |
502 (defun bookmark-make (name &optional annotation overwrite info-node) | 500 (defun bookmark-make (name &optional annotation overwrite info-node) |
503 "Make a bookmark named NAME. | 501 "Make a bookmark named NAME. |
504 Optional second arg ANNOTATION gives it an annotation. | 502 Optional second arg ANNOTATION gives it an annotation. |
505 Optional third arg OVERWRITE means replace any existing bookmarks with | 503 Optional third arg OVERWRITE means replace any existing bookmarks with |
978 (defun bookmark-buffer-name () | 976 (defun bookmark-buffer-name () |
979 "Return the name of the current buffer's file, non-directory. | 977 "Return the name of the current buffer's file, non-directory. |
980 In Info, return the current node." | 978 In Info, return the current node." |
981 (cond | 979 (cond |
982 ;; Are we in Info? | 980 ;; Are we in Info? |
983 ((string-equal mode-name "Info") Info-current-node) | 981 ((derived-mode-p 'Info-mode) Info-current-node) |
984 ;; Or are we a file? | 982 ;; Or are we a file? |
985 (buffer-file-name (file-name-nondirectory buffer-file-name)) | 983 (buffer-file-name (file-name-nondirectory buffer-file-name)) |
986 ;; Or are we a directory? | 984 ;; Or are we a directory? |
987 ((and (boundp 'dired-directory) dired-directory) | 985 ((and (boundp 'dired-directory) dired-directory) |
988 (let* ((dirname (if (stringp dired-directory) | 986 (let* ((dirname (if (stringp dired-directory) |
1082 (list (bookmark-completing-read "Jump to bookmark" | 1080 (list (bookmark-completing-read "Jump to bookmark" |
1083 bookmark-current-bookmark))) | 1081 bookmark-current-bookmark))) |
1084 (unless bookmark | 1082 (unless bookmark |
1085 (error "No bookmark specified")) | 1083 (error "No bookmark specified")) |
1086 (bookmark-maybe-historicize-string bookmark) | 1084 (bookmark-maybe-historicize-string bookmark) |
1087 (let ((cell (bookmark-jump-internal bookmark))) | 1085 (let ((alist (bookmark-jump-internal bookmark))) |
1088 (and cell | 1086 (and alist |
1089 (switch-to-buffer (car cell)) | 1087 (switch-to-buffer (cadr (assq 'buffer alist))) |
1090 (goto-char (cdr cell)) | 1088 (goto-char (cadr (assq 'position alist))) |
1091 (progn (run-hooks 'bookmark-after-jump-hook) t) | 1089 (progn (run-hooks 'bookmark-after-jump-hook) t) |
1092 (if bookmark-automatically-show-annotations | 1090 (if bookmark-automatically-show-annotations |
1093 ;; if there is an annotation for this bookmark, | 1091 ;; if there is an annotation for this bookmark, |
1094 ;; show it in a buffer. | 1092 ;; show it in a buffer. |
1095 (bookmark-show-annotation bookmark))))) | 1093 (bookmark-show-annotation bookmark))))) |
1104 bookmark-current-bookmark))) | 1102 bookmark-current-bookmark))) |
1105 (if (> emacs-major-version 21) | 1103 (if (> emacs-major-version 21) |
1106 (list bkm) bkm))) | 1104 (list bkm) bkm))) |
1107 (when bookmark | 1105 (when bookmark |
1108 (bookmark-maybe-historicize-string bookmark) | 1106 (bookmark-maybe-historicize-string bookmark) |
1109 (let ((cell (bookmark-jump-internal bookmark))) | 1107 (let ((alist (bookmark-jump-internal bookmark))) |
1110 (and cell | 1108 (and alist |
1111 (switch-to-buffer-other-window (car cell)) | 1109 (switch-to-buffer-other-window (cadr (assq 'buffer alist))) |
1112 (goto-char (cdr cell)) | 1110 (goto-char (cadr (assq 'position alist))) |
1113 (if bookmark-automatically-show-annotations | 1111 (if bookmark-automatically-show-annotations |
1114 ;; if there is an annotation for this bookmark, | 1112 ;; if there is an annotation for this bookmark, |
1115 ;; show it in a buffer. | 1113 ;; show it in a buffer. |
1116 (bookmark-show-annotation bookmark)))))) | 1114 (bookmark-show-annotation bookmark)))))) |
1117 | 1115 |
1141 (funcall (or (bookmark-get-handler bookmark) | 1139 (funcall (or (bookmark-get-handler bookmark) |
1142 'bookmark-jump-noselect) | 1140 'bookmark-jump-noselect) |
1143 bookmark)) | 1141 bookmark)) |
1144 | 1142 |
1145 (defun bookmark-jump-noselect (str) | 1143 (defun bookmark-jump-noselect (str) |
1146 ;; a leetle helper for bookmark-jump :-) | 1144 ;; Helper for bookmark-jump. STR is a bookmark name, of the sort |
1147 ;; returns (BUFFER . POINT) | 1145 ;; accepted by `bookmark-get-bookmark'. |
1146 ;; | |
1147 ;; Return an alist '((buffer BUFFER) (position POSITION) ...) | |
1148 ;; indicating the bookmarked point within the specied buffer. Any | |
1149 ;; elements not documented here should be ignored. | |
1148 (bookmark-maybe-load-default-file) | 1150 (bookmark-maybe-load-default-file) |
1149 (let* ((file (expand-file-name (bookmark-get-filename str))) | 1151 (let* ((file (expand-file-name (bookmark-get-filename str))) |
1150 (forward-str (bookmark-get-front-context-string str)) | 1152 (forward-str (bookmark-get-front-context-string str)) |
1151 (behind-str (bookmark-get-rear-context-string str)) | 1153 (behind-str (bookmark-get-rear-context-string str)) |
1152 (place (bookmark-get-position str)) | 1154 (place (bookmark-get-position str)) |
1177 (if behind-str | 1179 (if behind-str |
1178 (if (search-backward behind-str (point-min) t) | 1180 (if (search-backward behind-str (point-min) t) |
1179 (goto-char (match-end 0)))) | 1181 (goto-char (match-end 0)))) |
1180 ;; added by db | 1182 ;; added by db |
1181 (setq bookmark-current-bookmark str) | 1183 (setq bookmark-current-bookmark str) |
1182 (cons (current-buffer) (point)))) | 1184 `((buffer ,(current-buffer)) (position ,(point))))) |
1183 | 1185 |
1184 ;; Else unable to find the marked file, so ask if user wants to | 1186 ;; Else unable to find the marked file, so ask if user wants to |
1185 ;; relocate the bookmark, else remind them to consider deletion. | 1187 ;; relocate the bookmark, else remind them to consider deletion. |
1186 (ding) | 1188 (ding) |
1187 (if (y-or-n-p (concat (file-name-nondirectory orig-file) | 1189 (if (y-or-n-p (concat (file-name-nondirectory orig-file) |
1294 (bookmark-maybe-historicize-string bookmark) | 1296 (bookmark-maybe-historicize-string bookmark) |
1295 (bookmark-maybe-load-default-file) | 1297 (bookmark-maybe-load-default-file) |
1296 (let ((orig-point (point)) | 1298 (let ((orig-point (point)) |
1297 (str-to-insert | 1299 (str-to-insert |
1298 (save-excursion | 1300 (save-excursion |
1299 (set-buffer (car (bookmark-jump-internal bookmark))) | 1301 (set-buffer (cadr (assq 'buffer (bookmark-jump-internal bookmark)))) |
1300 (buffer-string)))) | 1302 (buffer-string)))) |
1301 (insert str-to-insert) | 1303 (insert str-to-insert) |
1302 (push-mark) | 1304 (push-mark) |
1303 (goto-char orig-point))) | 1305 (goto-char orig-point))) |
1304 | 1306 |
1923 (let ((bmrk (bookmark-bmenu-bookmark)) | 1925 (let ((bmrk (bookmark-bmenu-bookmark)) |
1924 (menu (current-buffer)) | 1926 (menu (current-buffer)) |
1925 (pop-up-windows t)) | 1927 (pop-up-windows t)) |
1926 (delete-other-windows) | 1928 (delete-other-windows) |
1927 (switch-to-buffer (other-buffer)) | 1929 (switch-to-buffer (other-buffer)) |
1928 (let* ((pair (bookmark-jump-internal bmrk)) | 1930 (let* ((alist (bookmark-jump-internal bmrk)) |
1929 (buff (car pair)) | 1931 (buff (cadr (assq 'buffer alist))) |
1930 (pos (cdr pair))) | 1932 (pos (cadr (assq 'position alist)))) |
1931 (pop-to-buffer buff) | 1933 (pop-to-buffer buff) |
1932 (goto-char pos)) | 1934 (goto-char pos)) |
1933 (bury-buffer menu)))) | 1935 (bury-buffer menu)))) |
1934 | 1936 |
1935 | 1937 |
1943 (defun bookmark-bmenu-other-window () | 1945 (defun bookmark-bmenu-other-window () |
1944 "Select this line's bookmark in other window, leaving bookmark menu visible." | 1946 "Select this line's bookmark in other window, leaving bookmark menu visible." |
1945 (interactive) | 1947 (interactive) |
1946 (let ((bookmark (bookmark-bmenu-bookmark))) | 1948 (let ((bookmark (bookmark-bmenu-bookmark))) |
1947 (if (bookmark-bmenu-check-position) | 1949 (if (bookmark-bmenu-check-position) |
1948 (let* ((pair (bookmark-jump-internal bookmark)) | 1950 (let* ((alist (bookmark-jump-internal bookmark)) |
1949 (buff (car pair)) | 1951 (buff (cadr (assq 'buffer alist))) |
1950 (pos (cdr pair))) | 1952 (pos (cadr (assq 'position alist)))) |
1951 (switch-to-buffer-other-window buff) | 1953 (switch-to-buffer-other-window buff) |
1952 (goto-char pos) | 1954 (goto-char pos) |
1953 (set-window-point (get-buffer-window buff) pos) | 1955 (set-window-point (get-buffer-window buff) pos) |
1954 (bookmark-show-annotation bookmark))))) | 1956 (bookmark-show-annotation bookmark))))) |
1955 | 1957 |
1961 (let ((bookmark (bookmark-bmenu-bookmark)) | 1963 (let ((bookmark (bookmark-bmenu-bookmark)) |
1962 (pop-up-windows t) | 1964 (pop-up-windows t) |
1963 same-window-buffer-names | 1965 same-window-buffer-names |
1964 same-window-regexps) | 1966 same-window-regexps) |
1965 (if (bookmark-bmenu-check-position) | 1967 (if (bookmark-bmenu-check-position) |
1966 (let* ((pair (bookmark-jump-internal bookmark)) | 1968 (let* ((alist (bookmark-jump-internal bookmark)) |
1967 (buff (car pair)) | 1969 (buff (cadr (assq 'buffer alist))) |
1968 (pos (cdr pair))) | 1970 (pos (cadr (assq 'position alist)))) |
1969 (display-buffer buff) | 1971 (display-buffer buff) |
1970 (let ((o-buffer (current-buffer))) | 1972 (let ((o-buffer (current-buffer))) |
1971 ;; save-excursion won't do | 1973 ;; save-excursion won't do |
1972 (set-buffer buff) | 1974 (set-buffer buff) |
1973 (goto-char pos) | 1975 (goto-char pos) |
2223 | 2225 |
2224 (run-hooks 'bookmark-load-hook) | 2226 (run-hooks 'bookmark-load-hook) |
2225 | 2227 |
2226 (provide 'bookmark) | 2228 (provide 'bookmark) |
2227 | 2229 |
2228 ;;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6 | 2230 ;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6 |
2229 ;;; bookmark.el ends here | 2231 ;;; bookmark.el ends here |