* 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; 6+ 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] 6+ messages in thread
* Re: function to copy org buffer substring with link description only
2015-12-08 17:33 function to copy org buffer substring with link description only Paul
@ 2015-12-09 7:25 ` Alexis
0 siblings, 0 replies; 6+ 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] 6+ messages in thread
[parent not found: <mailman.1527.1449434757.31583.help-gnu-emacs@gnu.org>]
* 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
0 siblings, 0 replies; 6+ 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] 6+ messages in thread
* Re: function to copy org buffer substring with link description only
@ 2015-12-09 18:00 Paul
0 siblings, 0 replies; 6+ 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] 6+ messages in thread
* 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; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread
end of thread, other threads:[~2015-12-09 19:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-08 17:33 function to copy org buffer substring with link description only Paul
2015-12-09 7:25 ` Alexis
[not found] <mailman.1527.1449434757.31583.help-gnu-emacs@gnu.org>
2015-12-09 19:57 ` Gene
-- strict thread matches above, loose matches on Subject: below --
2015-12-09 18:00 Paul
2015-12-06 20:45 Paul
2015-12-08 6:54 ` Alexis
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).