Last active
December 15, 2015 14:38
-
-
Save EricCrosson/a5fbd76a3a896267583c to your computer and use it in GitHub Desktop.
Emacs Lisp to scroll between google results in a w3m search. This script looks for the regex associated with each result, and ensures that it has found a valid result by checking for the presence of a hyperlink. So far, she works great.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun w3m-first-or-subsequent-google-result () | |
"Move point to the first (or subsequent) google result. | |
See also \\[w3m-prev-google-result]." | |
(interactive) | |
(w3m-find-a-google-result)) | |
(defun w3m-prev-google-result () | |
"Move point to the previous google result. | |
Complimentary function to \\[w3m-first-or-subsequent-google-result]." | |
(interactive) | |
(w3m-find-a-google-result "t")) | |
(defun w3m-find-a-google-result (&optional BACKWARDS) | |
"Find the next google result in the desired direction. | |
BACK, when a non-nil stringp, will look for previous results." | |
(let ((domain "google.com") | |
(identifier "[[:digit:]]\\. ")) | |
(if (not (string-match domain (w3m-print-current-url))) | |
(message (concat "You are not on " domain)) ;exit | |
(if BACKWARDS | |
(progn | |
(when (save-excursion (re-search-backward identifier nil 'noerror)) | |
(previous-line) | |
(re-search-backward identifier) | |
(forward-char 3))) | |
;; else FORWARDS | |
(when (save-excursion (re-search-forward identifier nil 'noerror)) | |
(re-search-forward identifier) | |
(while (not (w3m-anchor)) | |
(re-search-forward identifier))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment