From mboxrd@z Thu Jan 1 00:00:00 1970 From: Miro Bezjak Subject: org-insert-link with HTML title as default description Date: Sat, 29 Sep 2012 14:23:44 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:45031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THw5r-0007Ba-IB for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 08:24:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THw5p-0008SA-Pr for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 08:24:27 -0400 Received: from mail-ia0-f169.google.com ([209.85.210.169]:61734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THw5p-0008S1-LA for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 08:24:25 -0400 Received: by iakh37 with SMTP id h37so127281iak.0 for ; Sat, 29 Sep 2012 05:24:24 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi all. I'm new to the whole emacs/elisp/org-mode thing and I have to say I'm amazed by it. Thank you for all the hard work. That having been said, I've hacked together two functions that are useful to me. I was wondering what are your thoughts on including their idea (but with a better implementation) to org-mode? I've done some reasonable googling but haven't concluded that org-mode has something similar. 8<------------------------------------------------------------------------ (defun my-org-insert-link () "Insert org link where default description is set to html title." (interactive) (let* ((url (read-string "URL: ")) (title (get-html-title-from-url url))) (org-insert-link nil url title))) (defun get-html-title-from-url (url) "Return content in tag." (let (x1 x2 (download-buffer (url-retrieve-synchronously url))) (save-excursion (set-buffer download-buffer) (beginning-of-buffer) (setq x1 (search-forward "<title>")) (search-forward "") (setq x2 (search-backward "<")) (buffer-substring-no-properties x1 x2)))) -------------------------------------------------------------------------->8 Cheers, Miro From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: org-insert-link with HTML title as default description Date: Sat, 29 Sep 2012 16:42:44 +0200 Message-ID: <87r4pklwkb.fsf@bzg.ath.cx> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:58248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THyFc-0005td-Lo for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 10:42:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THyFb-0004qZ-Id for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 10:42:40 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:63968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THyFb-0004qV-CA for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 10:42:39 -0400 Received: by weyu3 with SMTP id u3so2217440wey.0 for ; Sat, 29 Sep 2012 07:42:38 -0700 (PDT) In-Reply-To: (Miro Bezjak's message of "Sat, 29 Sep 2012 14:23:44 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Miro Bezjak Cc: emacs-orgmode@gnu.org Hi Miro, Miro Bezjak writes: > That having been said, I've hacked together two functions that are > useful to me. I was wondering what are your thoughts on including > their idea (but with a better implementation) to org-mode? Nice. I'm not really in favor of including this command because it depends on whether the web is accessible or not. When it is, I guess most people store links with C-c C-l (in w3m) or use a capture template -- but some might enjoy your hack. IMHO this is a good candidates for the hacks we add on this page: http://orgmode.org/worg/org-hacks.html If you want to contribute to Worg please send me your public key. Thanks! -- Bastien From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sylvain Rousseau Subject: Re: org-insert-link with HTML title as default description Date: Sat, 29 Sep 2012 17:09:15 +0200 Message-ID: References: <87r4pklwkb.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:59342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THyfO-0001Rg-RU for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 11:09:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THyfN-00051p-Pp for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 11:09:18 -0400 Received: from mail-lb0-f169.google.com ([209.85.217.169]:49872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THyfN-00051j-IU for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 11:09:17 -0400 Received: by lbok6 with SMTP id k6so3068998lbo.0 for ; Sat, 29 Sep 2012 08:09:16 -0700 (PDT) In-Reply-To: <87r4pklwkb.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org, Miro Bezjak Hi Miro and Bastien, This can be done by setting the function `org-make-link-description-function'. However when set, the function is supposed to handle all type of links and return a string no matter what. There is no fallback mechanism. Here is a patch that fixes it: diff --git a/lisp/org.el b/lisp/org.el index bdb85de..3630623 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9527,10 +9527,12 @@ Use TAB to complete link prefixes, then RET for type-spe (setq desc path)))) (if org-make-link-description-function - (setq desc (funcall org-make-link-description-function link desc)) - (if default-description (setq desc default-description) - (setq desc (or (and auto-desc desc) - (read-string "Description: " desc))))) + (setq desc (or (funcall org-make-link-description-function link desc) + desc))) + + (if default-description (setq desc default-description) + (setq desc (or (and auto-desc desc) + (read-string "Description: " desc)))) (unless (string-match "\\S-" desc) (setq desc nil)) (if remove (apply 'delete-region remove)) For example my `org-make-link-description-function' is: (setq org-link-to-description '(("\\`file:.*/\\([^/:]+\\)\\(::.*\\)" . "\\1") ("\\`file:.*/\\([^/:]+\\)" . "\\1"))) (setq org-make-link-description-function (lambda (link description) (let ((found (assoc-default link org-link-to-description 'string-match))) (cond ((stringp found) (match-substitute-replacement found t nil link)))))) HTH, Sylvain. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Miro Bezjak Subject: Re: org-insert-link with HTML title as default description Date: Sat, 29 Sep 2012 20:43:12 +0200 Message-ID: References: <87r4pklwkb.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:37068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TI214-0002zP-9g for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 14:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TI213-0007dp-Au for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 14:43:54 -0400 Received: from mail-ie0-f169.google.com ([209.85.223.169]:39530) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TI213-0007dd-5v for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 14:43:53 -0400 Received: by ied10 with SMTP id 10so10829433ied.0 for ; Sat, 29 Sep 2012 11:43:52 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sylvain Rousseau Cc: Bastien , emacs-orgmode@gnu.org Hi Sylvain, Bastien, I have indeed noticed `org-make-link-description-function'. Though, from its documentation I've somehow concluded that it makes the final (and not default) description. By rereading documentation and source code for `org-insert-link', it appears that with addition of Sylvain's patch I could indeed use `org-make-link-description-function' and not wrap around `org-insert-link'. Cheers, Miro P.S. I'm sending SSH public key in a separate mail. On Sat, Sep 29, 2012 at 5:09 PM, Sylvain Rousseau wrote: > Hi Miro and Bastien, > > This can be done by setting the function > `org-make-link-description-function'. However when set, the function > is supposed to handle all type of links and return a string no matter > what. There is no fallback mechanism. Here is a patch that fixes it: > > > diff --git a/lisp/org.el b/lisp/org.el > index bdb85de..3630623 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -9527,10 +9527,12 @@ Use TAB to complete link prefixes, then RET for type-spe > (setq desc path)))) > > (if org-make-link-description-function > - (setq desc (funcall org-make-link-description-function link desc)) > - (if default-description (setq desc default-description) > - (setq desc (or (and auto-desc desc) > - (read-string "Description: " desc))))) > + (setq desc (or (funcall org-make-link-description-function link desc) > + desc))) > + > + (if default-description (setq desc default-description) > + (setq desc (or (and auto-desc desc) > + (read-string "Description: " desc)))) > > (unless (string-match "\\S-" desc) (setq desc nil)) > (if remove (apply 'delete-region remove)) > > > For example my `org-make-link-description-function' is: > > (setq org-link-to-description > '(("\\`file:.*/\\([^/:]+\\)\\(::.*\\)" . "\\1") > ("\\`file:.*/\\([^/:]+\\)" . "\\1"))) > > (setq org-make-link-description-function > (lambda (link description) > (let ((found (assoc-default link org-link-to-description > 'string-match))) > (cond > ((stringp found) (match-substitute-replacement found t > nil link)))))) > > > HTH, > > Sylvain. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: org-insert-link with HTML title as default description Date: Sat, 29 Sep 2012 22:53:47 +0200 Message-ID: <874nmgh7ok.fsf@bzg.ath.cx> References: <87r4pklwkb.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:38822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TI42i-0000wd-PV for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 16:53:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TI42h-0000sp-RN for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 16:53:44 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:47397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TI42h-0000sk-Ky for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 16:53:43 -0400 Received: by weyu3 with SMTP id u3so2336180wey.0 for ; Sat, 29 Sep 2012 13:53:42 -0700 (PDT) In-Reply-To: (Sylvain Rousseau's message of "Sat, 29 Sep 2012 17:09:15 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sylvain Rousseau Cc: emacs-orgmode@gnu.org, Miro Bezjak Hi Sylvain, Sylvain Rousseau writes: > This can be done by setting the function > `org-make-link-description-function'. However when set, the function > is supposed to handle all type of links and return a string no matter > what. There is no fallback mechanism. Here is a patch that fixes it: Thanks for pointing at this -- I implemented a different fallback that interactively prompt for a description when the adhoc function fails (I also prevented an error in this function to stop the insertion of a link.) Let me know if this is okay for you. Best, -- Bastien From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sylvain Rousseau Subject: Re: org-insert-link with HTML title as default description Date: Sun, 30 Sep 2012 01:00:24 +0200 Message-ID: References: <87r4pklwkb.fsf@bzg.ath.cx> <874nmgh7ok.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TI61K-0006tU-Kd for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 19:00:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TI61J-0008ER-Pr for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 19:00:26 -0400 Received: from mail-lb0-f169.google.com ([209.85.217.169]:38131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TI61J-0008Dr-If for emacs-orgmode@gnu.org; Sat, 29 Sep 2012 19:00:25 -0400 Received: by lbok6 with SMTP id k6so3240216lbo.0 for ; Sat, 29 Sep 2012 16:00:24 -0700 (PDT) In-Reply-To: <874nmgh7ok.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org, Miro Bezjak This is definitely better! Your version is actually more faithful to the original one as it ignores `default-description' when `org-make-link-description-function' is set (and succeed). Cheers, Sylvain.