# HG changeset patch # User Richard M. Stallman # Date 794953057 0 # Node ID d6d3905ec5508cf09e7451f3bc88ef8ad3b7f355 # Parent e43125b71452b6087a13b2d730ba3ba288135fe8 (bookmark-buffer-name): Be smarter about deducing a name. (bookmark-insert-buffer-name): Use bookmark-buffer-name. Replaces bookmark-insert-current-file-name. (bookmark-make-cell): Use set-text-properties, not format, to clear text properties. diff -r e43125b71452 -r d6d3905ec550 lisp/bookmark.el --- a/lisp/bookmark.el Sat Mar 11 19:13:52 1995 +0000 +++ b/lisp/bookmark.el Sat Mar 11 20:17:37 1995 +0000 @@ -5,7 +5,7 @@ ;; Author: Karl Fogel ;; Maintainer: Karl Fogel ;; Created: July, 1993 -;; Version: 2.6.5 +;; Version: 2.6.6 ;; Keywords: bookmarks, placeholders, annotations ;;; Summary: @@ -68,7 +68,7 @@ ;; LCD Archive Entry: ;; bookmark|Karl Fogel|kfogel@cyclic.com| ;; Setting bookmarks in files or directories, jumping to them later.| -;; 06-March-1995|Version: 2.6.5|~/misc/bookmark.el.Z| +;; 06-March-1995|Version: 2.6.6|~/misc/bookmark.el.Z| ;; Enough with the credits already, get on to the good stuff: @@ -446,18 +446,22 @@ (front-context-string . (, (if (>= (- (point-max) (point)) bookmark-search-size) ;; strip text props via `format': - (format "%s" + (let ((string (buffer-substring (point) - (+ (point) bookmark-search-size))) + (+ (point) bookmark-search-size)))) + (set-text-properties 0 (length string) nil string) + string) nil))) (rear-context-string . (, (if (>= (- (point) (point-min)) bookmark-search-size) ;; strip text props via `format': - (format "%s" + (let ((string (buffer-substring (point) - (- (point) bookmark-search-size))) + (- (point) bookmark-search-size)))) + (set-text-properties 0 (length string) nil string) + string) nil))) (position . (, (point))) (annotation . (, annotation))))) @@ -668,7 +672,7 @@ (progn (define-key now-map "\C-w" 'bookmark-yank-word) (define-key now-map "\C-v" - 'bookmark-insert-current-file-name) + 'bookmark-insert-buffer-name) (define-key now-map "\C-u" 'bookmark-insert-current-bookmark)) now-map))) @@ -841,20 +845,44 @@ (save-excursion (set-buffer bookmark-current-buffer) bookmark-current-bookmark))) - (if str (insert str) (bookmark-insert-current-file-name)))) + (if str (insert str) (bookmark-insert-buffer-name)))) -(defun bookmark-insert-current-file-name () +(defun bookmark-insert-buffer-name () ;; insert the name (sans path) of the current file into the bookmark ;; name that is being set. (interactive) (let ((str (save-excursion (set-buffer bookmark-current-buffer) - (file-name-nondirectory (bookmark-buffer-file-name))))) + (bookmark-buffer-name)))) (insert str))) +(defun bookmark-buffer-name () + "Return the name of the current buffer's file, non-directory. +In Info, return the current node." + (cond + ;; Are we in Info? + ((string-equal mode-name "Info") Info-current-node) + ;; Or are we a file? + (buffer-file-name (file-name-nondirectory buffer-file-name)) + ;; Or are we a directory? + ((and (boundp 'dired-directory) dired-directory) + (let* ((dirname (if (stringp dired-directory) + dired-directory + (car dired-directory))) + (idx (1- (length dirname)))) + ;; Strip the trailing slash. + (if (= ?/ (aref dirname idx)) + (file-name-nondirectory (substring dirname 0 idx)) + ;; Else return the current-buffer + (buffer-name (current-buffer))))) + ;; If all else fails, use the buffer's name. + (t + (buffer-name (current-buffer))))) + + (defun bookmark-yank-word () (interactive) ;; get the next word from the buffer and append it to the name of @@ -883,19 +911,6 @@ (car dired-directory)))))) -(defun bookmark-buffer-name () - "Return the name of the current buffer in a way useful for bookmarks. -For example, if this is a Info buffer, return the Info node's name." - (if (string-equal mode-name "Info") - Info-current-node - (or - buffer-file-name - (if (and (boundp 'dired-directory) dired-directory) - (if (stringp dired-directory) - dired-directory - (car dired-directory)))))) - - (defun bookmark-maybe-load-default-file () (and (not bookmarks-already-loaded) (null bookmark-alist) @@ -1081,7 +1096,7 @@ (interactive) (insert old))) (define-key now-map "\C-v" - 'bookmark-insert-current-file-name)) + 'bookmark-insert-buffer-name)) now-map))))) (progn (bookmark-set-name old newname)