unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Elisp function(s) to get the most recent n urls in a buffer
@ 2006-06-19  6:22 Brett  Kelly
  2006-06-19 15:16 ` vfoley
  0 siblings, 1 reply; 2+ messages in thread
From: Brett  Kelly @ 2006-06-19  6:22 UTC (permalink / raw)


This is my first foray into actual elisp programming, so be gentle ;)

My idea is this: I'd like to be able to execute a function in ERC
(emacs IRC client) to open a new buffer and show me the last n urls
that appear in the ERC buffer.  From there, I'd like to select (using
RET) one url, have it open in my browser (using browse-url-at-point, I
imagine) and have the list buffer close and return me to the ERC buffer
from which I called the function.

So, I'm attempting to write a function that builds and returns a list
of the last n urls in a buffer.  Here's what I've got so far:

(setf urllist '())

(defun get-urls (loc count)
  (interactive)
  (save-excursion
    (goto-char loc)
    (while (> count (length 'urllist))
    (progn
      (- (search-backward-regexp "http:") 5)
      (cons (thing-at-point 'url) '(urllist))
      (goto-char (- point 1)))
    ('urllist))))

I'm not really having a problem, per se - just looking for some
guidance and some style recommendations.  Assuming this is somewhat
correct (or at least on the right track), what would be my next step?

Thanks!

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

* Re: Elisp function(s) to get the most recent n urls in a buffer
  2006-06-19  6:22 Elisp function(s) to get the most recent n urls in a buffer Brett  Kelly
@ 2006-06-19 15:16 ` vfoley
  0 siblings, 0 replies; 2+ messages in thread
From: vfoley @ 2006-06-19 15:16 UTC (permalink / raw)


You know that I'm not expert, but without looking at how you wrote your
function, here's the solution I came up with:

(defun get-last-urls (count)

  (let ((urls '()))

    (save-excursion

      (while (< (length urls) count)

        (search-backward-regexp "\\(http://.*\\)\\b")

        (add-to-list 'urls (match-string 0))))

    urls))


It seems cleaner than your version and doesn't use a global variable.
Upon looking at your code, I see that you specifiy the line at which
you want to start looking, that would be easy to add.

Vince

Brett  Kelly wrote:
> This is my first foray into actual elisp programming, so be gentle ;)
>
> My idea is this: I'd like to be able to execute a function in ERC
> (emacs IRC client) to open a new buffer and show me the last n urls
> that appear in the ERC buffer.  From there, I'd like to select (using
> RET) one url, have it open in my browser (using browse-url-at-point, I
> imagine) and have the list buffer close and return me to the ERC buffer
> from which I called the function.
>
> So, I'm attempting to write a function that builds and returns a list
> of the last n urls in a buffer.  Here's what I've got so far:
>
> (setf urllist '())
>
> (defun get-urls (loc count)
>   (interactive)
>   (save-excursion
>     (goto-char loc)
>     (while (> count (length 'urllist))
>     (progn
>       (- (search-backward-regexp "http:") 5)
>       (cons (thing-at-point 'url) '(urllist))
>       (goto-char (- point 1)))
>     ('urllist))))
>
> I'm not really having a problem, per se - just looking for some
> guidance and some style recommendations.  Assuming this is somewhat
> correct (or at least on the right track), what would be my next step?
> 
> Thanks!

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

end of thread, other threads:[~2006-06-19 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-19  6:22 Elisp function(s) to get the most recent n urls in a buffer Brett  Kelly
2006-06-19 15:16 ` vfoley

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).