all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* function to copy org buffer substring with link description only
@ 2015-12-06 20:45 Paul
  2015-12-08  6:54 ` Alexis
  0 siblings, 1 reply; 10+ messages in thread
From: Paul @ 2015-12-06 20:45 UTC (permalink / raw)
  To: help-gnu-emacs

Hallo people.

(buffer-substring-no-properties (point) (mark)) on some part of an org 
buffer that contains a link returns the following example:

"while [[(some-link)][description]] does not"


Do You know a ready to use function that would return the following?:

"while description does not"

best regards,
Paul



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: function to copy org buffer substring with link description only
  2015-12-06 20:45 Paul
@ 2015-12-08  6:54 ` Alexis
  0 siblings, 0 replies; 10+ messages in thread
From: Alexis @ 2015-12-08  6:54 UTC (permalink / raw)
  To: Paul; +Cc: help-gnu-emacs


Paul <mafeuser@gmail.com> writes:

> (buffer-substring-no-properties (point) (mark)) on some part of 
> an org buffer that contains a link returns the following 
> example:
>
> "while [[(some-link)][description]] does not"
>
>
> Do You know a ready to use function that would return the 
> following?:
>
> "while description does not"

i'm not aware of any existing function that does this, so here's a 
function that's at least a start:

#+BEGIN_SRC emacs-lisp

    (defun org-delinkify-region (start end) 
      "Replace all Org-style links within the region with only the 
    link description text, and return the result." 
      (interactive "r") (let ((text 
      (buffer-substring-no-properties start end))) 
        (with-temp-buffer 
          (insert text) (goto-char (point-min)) (while 
          (re-search-forward "\\[\\[[^\\]+?]\\[\\(.+?\\)]\\]" 
          (point-max) t) 
            (replace-match (match-string 1))) 
          (buffer-substring (point-min) (point-max)))))

#+END_SRC 

Hope that helps!


Alexis.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: function to copy org buffer substring with link description only
@ 2015-12-08 17:33 Paul
  2015-12-09  7:25 ` Alexis
  0 siblings, 1 reply; 10+ messages in thread
From: Paul @ 2015-12-08 17:33 UTC (permalink / raw)
  To: flexibeast, help-gnu-emacs

thank YOu for the function

I believe that there must be something ready to be used, because 
org-mode does provide function that is able to export document or its 
part as text file. Of course such function probably removes more 
elements than link only, but that would be no harm.

best regards



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: function to copy org buffer substring with link description only
  2015-12-08 17:33 Paul
@ 2015-12-09  7:25 ` Alexis
  0 siblings, 0 replies; 10+ messages in thread
From: Alexis @ 2015-12-09  7:25 UTC (permalink / raw)
  To: Paul; +Cc: help-gnu-emacs


Paul <mafeuser@gmail.com> writes:

> thank YOu for the function
>
> I believe that there must be something ready to be used, because 
> org-mode does provide function that is able to export document 
> or its  part as text file. Of course such function probably 
> removes more  elements than link only, but that would be no 
> harm.

Oh, well, if you're not worried about affecting other elements, 
then you could wrap the `org-export-as` function like so:

#+BEGIN_SRC emacs-lisp

    (defun org-delinkify-region-2 () 
      "Replace all Org-style links within the region with only the 
    link description text, and return the result." 
      (interactive) (org-export-as 'ascii nil t t)) 

#+END_SRC 

The four arguments to `org-export-as` mean:

- Use the 'ascii export backend;
- Don't transcode the sub-tree at point; we're relying on 
  `org-export-as` working on the 
  region if the region is active.
- Don't export the contents of hidden elements.
- Don't add a surrounding template.

Note that `ox-ascii.el`, which defines the 'ascii export backend, 
/does/ have an `ox-ascii-link` function, but that function needs 
to be /passed/ the 'description' part of the link, the very thing 
we want to extract. In usual usage, this extraction is done by 
building a parse tree of an Org buffer, then calling 
`ox-ascii-link` with the relevant parse tree data for all links in 
the parse tree. So if i understand correctly, my code above is 
probably as simple as one can get for your use-case.

Hope that helps!


Alexis.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: function to copy org buffer substring with link description only
@ 2015-12-09 18:00 Paul
  0 siblings, 0 replies; 10+ messages in thread
From: Paul @ 2015-12-09 18:00 UTC (permalink / raw)
  To: help-gnu-emacs

That's the function I was looking for!

The missing part for me is to have the same signature as 
`buffer-substring` has, but this is much easier task and I should manage.

Thank You very much for Your help!!!

best regards!



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: function to copy org buffer substring with link description only
       [not found] <mailman.1527.1449434757.31583.help-gnu-emacs@gnu.org>
@ 2015-12-09 19:57 ` Gene
  2015-12-29 21:28   ` #org #annotate #lentic.el #annotate.el -- was " Gene
  0 siblings, 1 reply; 10+ messages in thread
From: Gene @ 2015-12-09 19:57 UTC (permalink / raw)
  To: help-gnu-emacs

On Sunday, December 6, 2015 at 3:46:00 PM UTC-5, Paul wrote:
> Hallo people.
> 
> (buffer-substring-no-properties (point) (mark)) on some part of an org 
> buffer that contains a link returns the following example:
> 
> "while [[(some-link)][description]] does not"
> 
> 
> Do You know a ready to use function that would return the following?:
> 
> "while description does not"
> 
> best regards,
> Paul

I think you might want to consider how you'd use this in practice.
It seems that you want to perform a destructive, non-restorable edit, rather than using two views of the same data via lentic or such.
As the string returned by the example contains the ASCII text of/for an org link this string can be parsed via split-string for both "[[" and "]]" to find beginning and end of the link to use as point and mark.
Or -- if you think about it -- searching for "][" should drop the cursor/point at the start of the description string of interest which ends at "]]"

As a general pointer/clue, `elt' is your friend because it operates on any sequence ... both strings and vectors in your case.
The structure of an org-mode link is a vector containing two vectors.
The description can be stripped from the vector either as a vector or while it's embedded in the string produced from the substring function.

The function which generates an org link is org-make-link-string.
Perhaps if you read the source for that function you will discover how links are assembled and therein obtain insights into how to disassemble them.

Here's a snippet of some code I crafted while going the other way ... starting with an URL then generating an org-mode link:

(defun 
  ddg2org-link 
 (
  lst ; the argument
 )
 "For every duckduckgo URL in lst produce an org-mode link"
 (interactive)
 (mapcar
 (lambda (ddg-URL)
    (org-make-link-string 
        ddg-URL              ; LINK
        (mapconcat
           #'identity                    ; FUNCTION 
           (split-string 
            (cadr                   ;\
              (split-string         ; \
                ddg-URL ; STRING    ;  > ; SEQUENCE 
               "?q="    ; SEPARATOR ; /
              )                     ;/
             )
             "%20"                       ; SEPARATOR for split-string
            );split-string
           " "                           ; SEPARATOR for mapconcat
        ) ; mapconcat
   ) ;org-make-link-string
  ) ; lambda
  lst
 );mapcar
)

; test it with a list of ddg URLs
(ddg2org-link 
'(
  "https://duckduckgo.com/html/?q=monsters%20are%20real%20stephen%20king"
  "https://duckduckgo.com/html/?q=love%20map"
))


I hope these clues help you think your way through to a workable solution.

Cheers!


^ permalink raw reply	[flat|nested] 10+ messages in thread

* #org #annotate #lentic.el #annotate.el -- was Re: function to copy org buffer substring with link description only
  2015-12-09 19:57 ` function to copy org buffer substring with link description only Gene
@ 2015-12-29 21:28   ` Gene
  2015-12-30  1:39     ` Drew Adams
  2016-01-07 21:15     ` Phillip Lord
  0 siblings, 2 replies; 10+ messages in thread
From: Gene @ 2015-12-29 21:28 UTC (permalink / raw)
  To: help-gnu-emacs

This problem of only wanting half of the info encapsulated in an org link resulted in some possibly-valuable follow-on thoughts.

A few days ago I was familiarizing myself with annotate.el which allows a file of annotations to be associated with a given file without that file being modified.
Then today, I noticed org-cliplink

 org-cliplink       20151229.... available  melpa      insert org-mode links 

It dawned on me that whether one only wants the URL of a link XOR the description a link for one's immediate purposes one MIGHT want the otherwise discarded information to be saved/retained in an annotation file -- perhaps by functions within annotation.el -- for possible future use, for use in a bibliography of sorts, etc.

Also, given the ability to use lenticular text with emacs it might be nice if the target text created by removing the non-descriptive part of an org link could be treated as lenticular text of sorts wherein the description would used as if literal text while the URL were retained in some way as a silent, invisible partner.

Also, the original problem seems ready-made for an org export operation capable of producing plain text.

Just some food for thought for developers.

Cheers!


^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: #org #annotate #lentic.el #annotate.el -- was Re: function to copy org buffer substring with link description only
  2015-12-29 21:28   ` #org #annotate #lentic.el #annotate.el -- was " Gene
@ 2015-12-30  1:39     ` Drew Adams
  2016-01-07 21:15     ` Phillip Lord
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2015-12-30  1:39 UTC (permalink / raw)
  To: Gene, help-gnu-emacs

> A few days ago I was familiarizing myself with annotate.el which allows a
> file of annotations to be associated with a given file without that file
> being modified.

[OT] FWIW, you can also bookmark a file (including in multiple places),
and a bookmark can have an annotation.  That gives you any number of
annotations for a file, each addressed directly.

If you use Bookmark+ then a bookmark annotation is in Org mode by
default, and an annotation can itself be a pointer to a separate
Org file (as opposed to saving annotations along with the bookmarks
they annotate, in your bookmarks file).

http://www.emacswiki.org/emacs/BookmarkPlus



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: #org #annotate #lentic.el #annotate.el -- was Re: function to copy org buffer substring with link description only
  2015-12-29 21:28   ` #org #annotate #lentic.el #annotate.el -- was " Gene
  2015-12-30  1:39     ` Drew Adams
@ 2016-01-07 21:15     ` Phillip Lord
  2016-01-08  0:52       ` Gene Sullivan
  1 sibling, 1 reply; 10+ messages in thread
From: Phillip Lord @ 2016-01-07 21:15 UTC (permalink / raw)
  To: Gene; +Cc: help-gnu-emacs

Gene <gene.sullivan@gmail.com> writes:
> Also, given the ability to use lenticular text with emacs it might be nice if
> the target text created by removing the non-descriptive part of an org link
> could be treated as lenticular text of sorts wherein the description would
> used as if literal text while the URL were retained in some way as a silent,
> invisible partner.


I am not 100% sure what you want here; are you after something that is
just a visualisation? I thought that org does that already -- i.e. it
just makes the link invisible and leaves just the description.

Phil



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: #org #annotate #lentic.el #annotate.el -- was Re: function to copy org buffer substring with link description only
  2016-01-07 21:15     ` Phillip Lord
@ 2016-01-08  0:52       ` Gene Sullivan
  0 siblings, 0 replies; 10+ messages in thread
From: Gene Sullivan @ 2016-01-08  0:52 UTC (permalink / raw)
  To: Phillip Lord; +Cc: help-gnu-emacs

What I wanted is a means for helping those with an org-mode link to retain
ALL/both data rather than jettisoning either the URL or the description.

There seems a chasm between an org-mode file and each of the various
end-goal re-uses and/or destination file formats available via `export'.
I was attempting to brainstorm ways of preserving both data and the
relations between data within the org-mode file so it can be available for
possible future use ... while allowing someone hell-bent on only ONE use --
in a surface-structural `visualization' -- to use only the portions exposed
without destroying or discarding the portions of no immediate use.



On Thu, Jan 7, 2016 at 4:15 PM, Phillip Lord <phillip.lord@russet.org.uk>
wrote:

> Gene <gene.sullivan@gmail.com> writes:
> > Also, given the ability to use lenticular text with emacs it might be
> nice if
> > the target text created by removing the non-descriptive part of an org
> link
> > could be treated as lenticular text of sorts wherein the description
> would
> > used as if literal text while the URL were retained in some way as a
> silent,
> > invisible partner.
>
>
> I am not 100% sure what you want here; are you after something that is
> just a visualisation? I thought that org does that already -- i.e. it
> just makes the link invisible and leaves just the description.
>
> Phil
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-01-08  0:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1527.1449434757.31583.help-gnu-emacs@gnu.org>
2015-12-09 19:57 ` function to copy org buffer substring with link description only Gene
2015-12-29 21:28   ` #org #annotate #lentic.el #annotate.el -- was " Gene
2015-12-30  1:39     ` Drew Adams
2016-01-07 21:15     ` Phillip Lord
2016-01-08  0:52       ` Gene Sullivan
2015-12-09 18:00 Paul
  -- strict thread matches above, loose matches on Subject: below --
2015-12-08 17:33 Paul
2015-12-09  7:25 ` Alexis
2015-12-06 20:45 Paul
2015-12-08  6:54 ` Alexis

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.