aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Zlatanov2013-12-21 15:33:44 -0500
committerTed Zlatanov2013-12-21 15:33:44 -0500
commitd49fbfd6705117ce7e79586e8fa9e96e2d8dd128 (patch)
tree32c404035a6a52d3a34e3d5f49e07fe5d879a234
parent5e1901c179de7047e731064507a9ae7f9833977f (diff)
downloademacs-d49fbfd6705117ce7e79586e8fa9e96e2d8dd128.tar.gz
emacs-d49fbfd6705117ce7e79586e8fa9e96e2d8dd128.zip
eww: machinery to list browser history
* net/eww.el (eww-list-histories, eww-list-histories) (eww-history-browse, eww-history-quit, eww-history-kill) (eww-history-mode-map, eww-history-mode): New command and functions to list browser histories.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/net/eww.el103
2 files changed, 101 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 499794e3469..42fd827c38d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12013-12-21 Kenjiro NAKAYAMA <nakayamakenjiro@gmail.com>
2
3 * net/eww.el (eww-list-histories, eww-list-histories)
4 (eww-history-browse, eww-history-quit, eww-history-kill)
5 (eww-history-mode-map, eww-history-mode): New command and
6 functions to list browser histories.
7
12013-12-21 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> 82013-12-21 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
2 9
3 * net/eww.el (eww-back-url, eww-forward-url, eww-next-url) 10 * net/eww.el (eww-back-url, eww-forward-url, eww-next-url)
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index df53d80cf35..8bcfb4838b6 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -414,6 +414,7 @@ word(s) will be searched for via `eww-search-prefix'."
414 (define-key map "w" 'eww-copy-page-url) 414 (define-key map "w" 'eww-copy-page-url)
415 (define-key map "C" 'url-cookie-list) 415 (define-key map "C" 'url-cookie-list)
416 (define-key map "v" 'eww-view-source) 416 (define-key map "v" 'eww-view-source)
417 (define-key map "H" 'eww-list-histories)
417 418
418 (define-key map "b" 'eww-add-bookmark) 419 (define-key map "b" 'eww-add-bookmark)
419 (define-key map "B" 'eww-list-bookmarks) 420 (define-key map "B" 'eww-list-bookmarks)
@@ -433,6 +434,7 @@ word(s) will be searched for via `eww-search-prefix'."
433 ["Download" eww-download t] 434 ["Download" eww-download t]
434 ["View page source" eww-view-source] 435 ["View page source" eww-view-source]
435 ["Copy page URL" eww-copy-page-url t] 436 ["Copy page URL" eww-copy-page-url t]
437 ["List histories" eww-list-histories t]
436 ["Add bookmark" eww-add-bookmark t] 438 ["Add bookmark" eww-add-bookmark t]
437 ["List bookmarks" eww-list-bookmarks t] 439 ["List bookmarks" eww-list-bookmarks t]
438 ["List cookies" url-cookie-list t])) 440 ["List cookies" url-cookie-list t]))
@@ -471,15 +473,6 @@ word(s) will be searched for via `eww-search-prefix'."
471 ;;(setq buffer-read-only t) 473 ;;(setq buffer-read-only t)
472 ) 474 )
473 475
474(defun eww-save-history ()
475 (push (list :url eww-current-url
476 :title eww-current-title
477 :point (point)
478 :dom eww-current-dom
479 :source eww-current-source
480 :text (buffer-string))
481 eww-history))
482
483;;;###autoload 476;;;###autoload
484(defun eww-browse-url (url &optional _new-window) 477(defun eww-browse-url (url &optional _new-window)
485 (when (and (equal major-mode 'eww-mode) 478 (when (and (equal major-mode 'eww-mode)
@@ -1262,6 +1255,98 @@ Differences in #targets are ignored."
1262 (setq buffer-read-only t 1255 (setq buffer-read-only t
1263 truncate-lines t)) 1256 truncate-lines t))
1264 1257
1258;;; History code
1259
1260(defun eww-save-history ()
1261 (push (list :url eww-current-url
1262 :title eww-current-title
1263 :point (point)
1264 :dom eww-current-dom
1265 :source eww-current-source
1266 :text (buffer-string))
1267 eww-history))
1268
1269(defun eww-list-histories ()
1270 "List the eww-histories."
1271 (interactive)
1272 (when (null eww-history)
1273 (error "No eww-histories are defined"))
1274 (set-buffer (get-buffer-create "*eww history*"))
1275 (eww-history-mode)
1276 (let ((inhibit-read-only t)
1277 (domain-length 0)
1278 (title-length 0)
1279 url title format start)
1280 (erase-buffer)
1281 (dolist (history eww-history)
1282 (setq start (point))
1283 (setq domain-length (max domain-length (length (plist-get history :url))))
1284 (setq title-length (max title-length (length (plist-get history :title))))
1285 )
1286 (setq format (format "%%-%ds %%-%ds" title-length domain-length)
1287 header-line-format
1288 (concat " " (format format "Title" "URL")))
1289
1290 (dolist (history eww-history)
1291 (setq url (plist-get history :url))
1292 (setq title (plist-get history :title))
1293 (insert (format format title url))
1294 (insert "\n")
1295 (put-text-property start (point) 'eww-history history)
1296 )
1297 (goto-char (point-min)))
1298 (pop-to-buffer "*eww history*")
1299 )
1300
1301(defun eww-history-browse ()
1302 "Browse the history under point in eww."
1303 (interactive)
1304 (let ((history (get-text-property (line-beginning-position) 'eww-history)))
1305 (unless history
1306 (error "No history on the current line"))
1307 (eww-history-quit)
1308 (pop-to-buffer "*eww*")
1309 (eww-browse-url (plist-get history :url))))
1310
1311(defun eww-history-quit ()
1312 "Kill the current buffer."
1313 (interactive)
1314 (kill-buffer (current-buffer)))
1315
1316(defvar eww-history-kill-ring nil)
1317
1318(defun eww-history-kill ()
1319 "Kill the current history."
1320 (interactive)
1321 (let* ((start (line-beginning-position))
1322 (history (get-text-property start 'eww-history))
1323 (inhibit-read-only t))
1324 (unless history
1325 (error "No history on the current line"))
1326 (forward-line 1)
1327 (push (buffer-substring start (point)) eww-history-kill-ring)
1328 (delete-region start (point))
1329 (setq eww-history (delq history eww-history))
1330 ))
1331
1332(defvar eww-history-mode-map
1333 (let ((map (make-sparse-keymap)))
1334 (suppress-keymap map)
1335 (define-key map "q" 'eww-history-quit)
1336 (define-key map [(control k)] 'eww-history-kill)
1337 (define-key map "\r" 'eww-history-browse)
1338 (define-key map "n" 'next-error-no-select)
1339 (define-key map "p" 'previous-error-no-select)
1340 map))
1341
1342(define-derived-mode eww-history-mode nil "eww history"
1343 "Mode for listing eww-histories.
1344
1345\\{eww-history-mode-map}"
1346 (buffer-disable-undo)
1347 (setq buffer-read-only t
1348 truncate-lines t))
1349
1265(provide 'eww) 1350(provide 'eww)
1266 1351
1267;;; eww.el ends here 1352;;; eww.el ends here