From mboxrd@z Thu Jan 1 00:00:00 1970 From: James TD Smith Subject: [PATCH 2/5] Add a way to set a user-defined function to generate descriptions for links. Date: Sun, 16 Mar 2008 16:29:15 +0000 Message-ID: <20080316162806.23004.95932.stgit@nyarlathotep.internal> References: <20080316162417.23004.16993.stgit@nyarlathotep.internal> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JawJc-0001Uj-NX for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JawJb-0001Tk-Vy for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:32 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JawJb-0001Ta-Re for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:31 -0400 Received: from 81-86-40-42.dsl.pipex.com ([81.86.40.42] helo=yog-sothoth.internal) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JawJb-0007u7-2g for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:31 -0400 Received: from nyarlathotep.internal (Debian-exim@nyarlathotep.internal [10.0.0.5]) by yog-sothoth.internal (8.13.4/8.13.4) with ESMTP id m2GGTGqc015262 for ; Sun, 16 Mar 2008 16:29:16 GMT (envelope-from ahktenzero@dsl.pipex.com) Received: from [127.0.0.1] (helo=nyarlathotep.internal ident=ahktenzero) by nyarlathotep.internal with esmtp (Exim 4.69) (envelope-from ) id 1JavjX-0006E4-Vx for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 16:29:15 +0000 In-Reply-To: <20080316162417.23004.16993.stgit@nyarlathotep.internal> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org From: James TD Smith 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 "\\([^<]*\\)" (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))