* copy a link + hyperlink & text
@ 2016-06-03 18:27 Sharon Kimble
2016-06-03 18:55 ` Alex Kost
2016-06-04 4:33 ` John Mastro
0 siblings, 2 replies; 5+ messages in thread
From: Sharon Kimble @ 2016-06-03 18:27 UTC (permalink / raw)
To: help-emacs
[-- Attachment #1: Type: text/plain, Size: 358 bytes --]
How can I copy a link with the text and the hyperlink all at once from
either emacs w3m or from gnus please? Preferably all with one keypress?
It will be pasted into a org-mode document as its destination.
Thanks
Sharon.
--
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.4, fluxbox 1.3.7, emacs 25.0.94
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: copy a link + hyperlink & text
2016-06-03 18:27 copy a link + hyperlink & text Sharon Kimble
@ 2016-06-03 18:55 ` Alex Kost
2016-06-04 4:33 ` John Mastro
1 sibling, 0 replies; 5+ messages in thread
From: Alex Kost @ 2016-06-03 18:55 UTC (permalink / raw)
To: Sharon Kimble; +Cc: help-emacs
Sharon Kimble (2016-06-03 21:27 +0300) wrote:
> How can I copy a link with the text and the hyperlink all at once from
> either emacs w3m or from gnus please? Preferably all with one keypress?
> It will be pasted into a org-mode document as its destination.
I think for both gnus and w3m the default key binding is "u" (when the
point is placed on a link). I prefer to use "c" key, so I bind it like
this:
(with-eval-after-load 'gnus-art
(define-key gnus-article-mode-map (kbd "c") 'gnus-article-copy-string))
(with-eval-after-load 'w3m
(define-key w3m-mode-map (kbd "c") 'w3m-print-current-url))
--
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: copy a link + hyperlink & text
[not found] <mailman.771.1464978467.1216.help-gnu-emacs@gnu.org>
@ 2016-06-03 21:32 ` Emanuel Berg
0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2016-06-03 21:32 UTC (permalink / raw)
To: help-gnu-emacs
Sharon Kimble <boudiccas@skimble.plus.com>
writes:
> How can I copy a link with the text and the
> hyperlink all at once from either emacs w3m
> or from gnus please? Preferably all with one
> keypress? It will be pasted into a org-mode
> document as its destination.
I have a DWIM function to do that. If point is
at a link, it gets (kills) the link's
destination (the URL). If there is a literal
URL at point, it gets that. If nothing, it gets
the URL of the current w3m buffer.
For Gnus - perhaps it works there as well! (the
literal stuff) - otherwise it is a good idea to
have...
(defun w3m-kill-url-dwim ()
(interactive)
(let ((anchor-url (w3m-anchor)))
(if anchor-url (kill-new anchor-url)
(let ((literal-url (thing-at-point 'url)))
(if literal-url (kill-new literal-url)
(kill-new w3m-current-url) ))))
(message "killed: %s" (current-kill 0)) )
Code in context:
http://user.it.uu.se/~embe8573/conf/emacs-init/w3m/w3m-my.el
Bind it to "s" and "u":
http://user.it.uu.se/~embe8573/conf/emacs-init/w3m/w3m-keys.el
Don't thank me - I'll send an invoice :)
--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 45 Blogomatic articles -
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: copy a link + hyperlink & text
2016-06-03 18:27 copy a link + hyperlink & text Sharon Kimble
2016-06-03 18:55 ` Alex Kost
@ 2016-06-04 4:33 ` John Mastro
2016-06-04 4:56 ` John Mastro
1 sibling, 1 reply; 5+ messages in thread
From: John Mastro @ 2016-06-04 4:33 UTC (permalink / raw)
To: help-emacs; +Cc: Sharon Kimble
Sharon Kimble <boudiccas@skimble.plus.com> wrote:
> How can I copy a link with the text and the hyperlink all at once from
> either emacs w3m or from gnus please? Preferably all with one keypress?
> It will be pasted into a org-mode document as its destination.
By "the text" do you mean the link text you see in the rendered web
page? If so, I'm not aware of a w3m built-in function to get that,
though Alex and Emanuel provided solutions to get the linked-to URL in
w3m and gnus.
Here's something quick-and-dirty that kinda-sorta does what I believe
you're going for with w3m. I say kinda-sorta because (a) it only grabs
the full link text if point is on the first character, (b) I only
lightly tested it so there are probably some scenarios where it won't do
the right thing.
It copies the link-with-text in Org's external link format, since you
mentioned Org, but that would be easy to change.
(defun w3m-link-at-point ()
"Return a list of (URL LINK-TEXT) for the link at point."
(save-excursion
(let ((url (w3m-anchor)))
(when url
(let* ((beg (point))
(end (progn
(goto-char (next-single-property-change
beg 'w3m-href-anchor))
(point))))
(list url (buffer-substring-no-properties beg end)))))))
(defun w3m-copy-org-link ()
"Copy the link at point to the kill ring in Org's link format."
(interactive)
(let ((href (w3m-link-at-point)))
(if href
(kill-new (format "[[%s][%s]]" (car href) (cadr href)))
(user-error "No link at point"))))
Hope that helps
John
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: copy a link + hyperlink & text
2016-06-04 4:33 ` John Mastro
@ 2016-06-04 4:56 ` John Mastro
0 siblings, 0 replies; 5+ messages in thread
From: John Mastro @ 2016-06-04 4:56 UTC (permalink / raw)
To: help-emacs; +Cc: Sharon Kimble
John Mastro <john.b.mastro@gmail.com> wrote:
> Here's something quick-and-dirty that kinda-sorta does what I believe
> you're going for with w3m.
Here's a slight revision that tries to grab the full link text even if
point isn't on the first character. I have the sense there's a better
way to do it, but this seems to work.
(require 'subr-x)
(defun find-property-bounds (pos prop)
(save-excursion
(goto-char pos)
(let* ((val (get-text-property (point) prop))
(beg (progn (forward-char -1)
(while (eq (get-text-property (point) prop) val)
(forward-char -1))
(1+ (point))))
(end (next-single-property-change beg prop)))
(list beg end))))
(defun w3m-link-at-point ()
"Return a list of (URL LINK-TEXT) for the link at point."
(save-excursion
(when-let ((url (w3m-anchor)))
(let ((bounds (find-property-bounds (point) 'w3m-href-anchor)))
(list url (apply #'buffer-substring-no-properties bounds))))))
(defun w3m-copy-org-link ()
"Copy the link at point to the kill ring in Org link format."
(interactive)
(if-let ((link (w3m-link-at-point)))
(let ((org-link (format "[[%s][%s]]" (car link) (cadr link))))
(message "%s" org-link)
(kill-new org-link))
(user-error "No link at point")))
Hope that helps
John
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-04 4:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-03 18:27 copy a link + hyperlink & text Sharon Kimble
2016-06-03 18:55 ` Alex Kost
2016-06-04 4:33 ` John Mastro
2016-06-04 4:56 ` John Mastro
[not found] <mailman.771.1464978467.1216.help-gnu-emacs@gnu.org>
2016-06-03 21:32 ` Emanuel Berg
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).