emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] [PATCH 2/5] Add a way to set a user-defined function to ge


From: Carsten Dominik
Subject: Re: [Orgmode] [PATCH 2/5] Add a way to set a user-defined function to generate descriptions for links.
Date: Wed, 9 Apr 2008 17:15:20 +0200

Applied, but with renaming org-make-link-description to org-make-link- description-function.

Thanks.

- Carsten

On Mar 16, 2008, at 5:29 PM, James TD Smith wrote:

From: James TD Smith <address@hidden>

Below is an example which uses w3m to retrieve the titles of web pages to use as
link descriptions.

(require 'w3m)

(defun make-link-description (link desc)
 "Link description generator for orgmode"
 (cond ((string-match "https?:" link)
         (with-temp-buffer
           (w3m-retrieve link)
           (goto-char (point-min))
(if (search-forward-regexp "<title>\\([^<]*\\)</title>" (point- max) t)
               (url-unhex-string (match-string 1)))))
        (t (or desc link))))

(setq org-make-link-description 'make-link-description)

---

org.el |   37 +++++++++++++++++++++++++++----------
1 files changed, 27 insertions(+), 10 deletions(-)


diff --git a/org.el b/org.el
index 8fe8edd..021bd59 100644
--- a/org.el
+++ b/org.el
@@ -1209,6 +1209,15 @@ Changing this variable requires a restart of Emacs to become effective."
              (const :tag "Tags" tag)
              (const :tag "Timestamps" date)))

+(defcustom org-make-link-description nil
+  "Function to use to generate link descriptions from links. If
+nil the link location will be used. This function must take two
+parameters; the first is the link and the second the description
+org-insert-link has generated, and should return the description
+to use."
+  :group 'org-link
+  :type 'function)
+
(defgroup org-link-store nil
  "Options concerning storing links in Org-mode"
  :tag "Org Store Link"
@@ -12475,16 +12484,21 @@ be displayed in the buffer instead of the link. If there is already a link at point, this command will allow you to edit link
and description parts.

-With a \\[universal-argument] prefix, prompts for a file to link to. The file name can 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).
-
-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'."
+With a \\[universal-argument] prefix, prompts for a file to link
+to. The file name can 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).
+
+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'.
+
+If `org-make-link-description' is non-nil, this function will be
+called with the link target, and the result will be the default
+link description."
  (interactive "P")
  (let* ((wcf (current-window-configuration))
         (region (if (org-region-active-p)
@@ -12605,6 +12619,9 @@ With three \\[universal-argument] prefixes, negate the meaning of
        (if (equal desc origpath)
            (setq desc path))))

+    (if org-make-link-description
+       (setq desc (funcall org-make-link-description link desc)))
+
    (setq desc (read-string "Description: " desc))
    (unless (string-match "\\S-" desc) (setq desc nil))
    (if remove (apply 'delete-region remove))



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
address@hidden
http://lists.gnu.org/mailman/listinfo/emacs-orgmode





reply via email to

[Prev in Thread] Current Thread [Next in Thread]