From: James TD Smith <ahktenzero@dsl.pipex.com>
To: emacs-orgmode@gnu.org
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 [thread overview]
Message-ID: <20080316162806.23004.95932.stgit@nyarlathotep.internal> (raw)
In-Reply-To: <20080316162417.23004.16993.stgit@nyarlathotep.internal>
From: James TD Smith <ahktenzero@usa.net>
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))
next prev parent reply other threads:[~2008-03-16 17:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-16 16:27 [PATCH 0/5] Various patches James TD Smith
2008-03-16 16:28 ` [PATCH 1/5] Hide drawers after displaying an entry using org-clock-goto James TD Smith
2008-03-16 16:29 ` James TD Smith [this message]
2008-04-09 15:15 ` [PATCH 2/5] Add a way to set a user-defined function to generate descriptions for links Carsten Dominik
2008-03-16 16:29 ` [PATCH 3/5] Some improvements to org-table-export James TD Smith
2008-04-09 15:59 ` Carsten Dominik
2008-03-16 16:30 ` [PATCH 4/5] Add a new sort option, which sorts items by todo keyword James TD Smith, James TD Smith
2008-04-09 15:40 ` Carsten Dominik
2008-03-16 16:31 ` [PATCH 5/5] clipboard handling in remember templats James TD Smith
2008-04-09 15:32 ` Carsten Dominik
2008-04-09 17:35 ` James TD Smith
2008-03-16 18:29 ` [PATCH 4/5] Various patches James TD Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080316162806.23004.95932.stgit@nyarlathotep.internal \
--to=ahktenzero@dsl.pipex.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).