From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [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 Message-ID: <9E9B3058-5A35-4DA4-BB8C-26CC97512B48@science.uva.nl> References: <20080316162417.23004.16993.stgit@nyarlathotep.internal> <20080316162806.23004.95932.stgit@nyarlathotep.internal> Mime-Version: 1.0 (Apple Message framework v919.2) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JjdAq-000858-Dg for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:24 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JjdAp-00084U-4c for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:23 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JjdAo-00084N-UP for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:22 -0400 Received: from fg-out-1718.google.com ([72.14.220.157]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JjdAo-0004XX-ET for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:22 -0400 Received: by fg-out-1718.google.com with SMTP id d23so3721409fga.30 for ; Wed, 09 Apr 2008 09:29:20 -0700 (PDT) In-Reply-To: <20080316162806.23004.95932.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: James TD Smith Cc: emacs-orgmode@gnu.org 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 > > 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)) > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode