Explorar o código

Abbreviate absolute file names in links.

This is a bug fix.  When the option `org-link-file-path-type' has the
value `adaptive', absolute file names would not be abbreviated if they
are relative to the users home directory.  For any other values of
this variable except `noabbrev', absolute links are in fact
abbreviated, so the previous behavior is an inconsistency,
as noticed by Matt Lundin.

This patch fixes this problem and makes sure that also in this case,
file names are abbreviated.

Finally, the patch also fixes a structural bug that would ignore
the double C-u prefix if it was given.
Carsten Dominik %!s(int64=16) %!d(string=hai) anos
pai
achega
a80b84425b
Modificáronse 2 ficheiros con 21 adicións e 7 borrados
  1. 6 0
      lisp/ChangeLog
  2. 15 7
      lisp/org.el

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2008-11-04  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.el (org-insert-link): Abbreviate absolute files names in
+	links.  Also, fix a bug in which the double C-u prefix would not
+	be honored.
+
 2008-11-03  Carsten Dominik  <dominik@science.uva.nl>
 
 	* org.el (org-insert-heading): If buffer does not end with a

+ 15 - 7
lisp/org.el

@@ -6339,7 +6339,10 @@ This command can be called in any mode to insert a link in Org-mode syntax."
 (defun org-insert-link (&optional complete-file link-location)
   "Insert a link.  At the prompt, enter the link.
 
-Completion can be used to select a link previously stored with
+Completion can be used to insert any of the link protocol prefixes like
+http or ftp in use.
+
+The history can be used to select a link previously stored with
 `org-store-link'.  When the empty string is entered (i.e. if you just
 press RET at the prompt), the link defaults to the most recently
 stored link.  As SPC triggers completion in the minibuffer, you need to
@@ -6355,11 +6358,14 @@ With a \\[universal-argument] prefix, prompts for a file to link to. The file na
 be selected using completion. The path to the file will be relative to the
 current directory if the file is in the current directory or a subdirectory.
 Otherwise, the link will be the absolute path as completed in the minibuffer
-\(i.e. normally ~/path/to/file).
+\(i.e. normally ~/path/to/file).  You can configure this behavior using the
+option `org-link-file-path-type'.
 
 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
-the current directory or below. With three \\[universal-argument] prefixes, negate the meaning
-of `org-keep-stored-link-after-insertion'.
+the current directory or below.
+
+With three \\[universal-argument] prefixes, negate the meaning of
+`org-keep-stored-link-after-insertion'.
 
 If `org-make-link-description-function' is non-nil, this function will be
 called with the link target, and the result will be the default
@@ -6391,7 +6397,7 @@ used as the link location instead of reading one interactively."
       (setq remove (list (match-beginning 0) (match-end 0))
 	    link (read-string "Link: "
 			      (org-remove-angle-brackets (match-string 0)))))
-     ((equal complete-file '(4))
+     ((member complete-file '((4) (16)))
       ;; Completing read for file names.
       (setq file (read-file-name "File: "))
       (let ((pwd (file-name-as-directory (expand-file-name ".")))
@@ -6470,7 +6476,8 @@ used as the link location instead of reading one interactively."
 	     (origpath path)
 	     (case-fold-search nil))
 	(cond
-	 ((eq org-link-file-path-type 'absolute)
+	 ((or (eq org-link-file-path-type 'absolute)
+	      (equal complete-file '(16)))
 	  (setq path (abbreviate-file-name (expand-file-name path))))
 	 ((eq org-link-file-path-type 'noabbrev)
 	  (setq path (expand-file-name path)))
@@ -6484,7 +6491,8 @@ used as the link location instead of reading one interactively."
 			      (expand-file-name path))
 		;; We are linking a file with relative path name.
 		(setq path (substring (expand-file-name path)
-				      (match-end 0)))))))
+				      (match-end 0)))
+	      (setq path (abbreviate-file-name (expand-file-name path)))))))
 	(setq link (concat "file:" path))
 	(if (equal desc origpath)
 	    (setq desc path))))