I need to get weblinks from a buffer (http....) and put them into scratch buffer. This code partially works, but the weblinks are inserted in the same buffer.
I'm new at programming.
(defun get-weblinks ()
"Get weblinks from a buffer"
(interactive)
(let (p1 p2 url)
(while (search-forward "http")
(backward-char 4)
(setq p1 (point))
(search-forward "jpg")
(setq p2 (point))
(setq url (buffer-substring p1 p2))
(insert url "\n")
)))
How can I finish the function?
Thank you for your help.
re-search-forward
orre-search-backward
with an appropriate regex that matches the entire link; and then use(match-beginning 0)
and(match-end 0)
to get the points for the beginning and ending of the link -- assuming the regex matches everything. You can useM-x re-builder
to come up with a complete regexp; or you can Google for it and then check withre-builder
to see if it matches them all. I saw several examples in my brief Google searches dealing with the generalized type of links withhref
orsrc
, so you'll need to do some hunting. – lawlist Dec 03 '15 at 22:40push
the results into a list and then regurgitate the list when your all done -- e.g.,(let (result my-list) ... *while* search stuff (setq result "thelink") (push result my-list) ... move to wherever or whatever buffer ... (mapc (lambda (x) (insert x "\n")) my-list))
– lawlist Dec 03 '15 at 22:50This is very useful to me.
Thank you. @lawlist
– Lizardo Reyna Dec 04 '15 at 11:08