diff options
| author | Lars Magne Ingebrigtsen | 2013-06-26 18:54:48 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2013-06-26 18:54:48 +0200 |
| commit | 2b4f050643e66bbbe681a7e7e82dbdc5bf80fc7e (patch) | |
| tree | 227f432ee9277902d7f2bf465515e3e5b96ed05f | |
| parent | bace80138586ec3d166baaa511eced3fb54d040b (diff) | |
| download | emacs-2b4f050643e66bbbe681a7e7e82dbdc5bf80fc7e.tar.gz emacs-2b4f050643e66bbbe681a7e7e82dbdc5bf80fc7e.zip | |
Add bookmark support to eww
* net/eww.el (eww-mode): Undo isn't necessary in eww buffers,
probably.
(eww-mode-map): Add a menu bar.
(eww-add-bookmark): New command.
(eww-bookmark-mode): New mode and commands.
| -rw-r--r-- | lisp/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/net/eww.el | 174 | ||||
| -rw-r--r-- | lisp/url/ChangeLog | 1 | ||||
| -rw-r--r-- | lisp/url/url-cookie.el | 3 |
4 files changed, 178 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 11c7b2de534..ea99e5c126a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | * net/eww.el (eww-mode): Undo isn't necessary in eww buffers, | 3 | * net/eww.el (eww-mode): Undo isn't necessary in eww buffers, |
| 4 | probably. | 4 | probably. |
| 5 | (eww-mode-map): Add a menu bar. | 5 | (eww-mode-map): Add a menu bar. |
| 6 | (eww-add-bookmark): New command. | ||
| 7 | (eww-bookmark-mode): New mode and commands. | ||
| 6 | 8 | ||
| 7 | 2013-06-26 Glenn Morris <rgm@gnu.org> | 9 | 2013-06-26 Glenn Morris <rgm@gnu.org> |
| 8 | 10 | ||
diff --git a/lisp/net/eww.el b/lisp/net/eww.el index d56031a6f34..0fd6591e053 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el | |||
| @@ -337,6 +337,11 @@ word(s) will be searched for via `eww-search-prefix'." | |||
| 337 | (define-key map "w" 'eww-copy-page-url) | 337 | (define-key map "w" 'eww-copy-page-url) |
| 338 | (define-key map "C" 'url-cookie-list) | 338 | (define-key map "C" 'url-cookie-list) |
| 339 | 339 | ||
| 340 | (define-key map "b" 'eww-add-bookmark) | ||
| 341 | (define-key map "B" 'eww-list-bookmarks) | ||
| 342 | (define-key map [(meta n)] 'eww-next-bookmark) | ||
| 343 | (define-key map [(meta p)] 'eww-previous-bookmark) | ||
| 344 | |||
| 340 | (easy-menu-define nil map "" | 345 | (easy-menu-define nil map "" |
| 341 | '("eww" | 346 | '("eww" |
| 342 | ["Quit" eww-quit t] | 347 | ["Quit" eww-quit t] |
| @@ -348,6 +353,8 @@ word(s) will be searched for via `eww-search-prefix'." | |||
| 348 | ["Browse with external browser" eww-browse-with-external-browser t] | 353 | ["Browse with external browser" eww-browse-with-external-browser t] |
| 349 | ["Download" eww-download t] | 354 | ["Download" eww-download t] |
| 350 | ["Copy page URL" eww-copy-page-url t] | 355 | ["Copy page URL" eww-copy-page-url t] |
| 356 | ["Add bookmark" eww-add-bookmark t] | ||
| 357 | ["List bookmarks" eww-copy-page-url t] | ||
| 351 | ["List cookies" url-cookie-list t])) | 358 | ["List cookies" url-cookie-list t])) |
| 352 | map)) | 359 | map)) |
| 353 | 360 | ||
| @@ -366,6 +373,7 @@ word(s) will be searched for via `eww-search-prefix'." | |||
| 366 | 373 | ||
| 367 | (defun eww-save-history () | 374 | (defun eww-save-history () |
| 368 | (push (list :url eww-current-url | 375 | (push (list :url eww-current-url |
| 376 | :title eww-current-title | ||
| 369 | :point (point) | 377 | :point (point) |
| 370 | :text (buffer-string)) | 378 | :text (buffer-string)) |
| 371 | eww-history)) | 379 | eww-history)) |
| @@ -404,7 +412,8 @@ word(s) will be searched for via `eww-search-prefix'." | |||
| 404 | (erase-buffer) | 412 | (erase-buffer) |
| 405 | (insert (plist-get elem :text)) | 413 | (insert (plist-get elem :text)) |
| 406 | (goto-char (plist-get elem :point)) | 414 | (goto-char (plist-get elem :point)) |
| 407 | (setq eww-current-url (plist-get elem :url)))) | 415 | (setq eww-current-url (plist-get elem :url) |
| 416 | eww-current-title (plist-get elem :title)))) | ||
| 408 | 417 | ||
| 409 | (defun eww-next-url () | 418 | (defun eww-next-url () |
| 410 | "Go to the page marked `next'. | 419 | "Go to the page marked `next'. |
| @@ -929,6 +938,169 @@ The browser to used is specified by the `shr-external-browser' variable." | |||
| 929 | (setq count (1+ count))) | 938 | (setq count (1+ count))) |
| 930 | (expand-file-name file directory))) | 939 | (expand-file-name file directory))) |
| 931 | 940 | ||
| 941 | ;;; Bookmarks code | ||
| 942 | |||
| 943 | (defvar eww-bookmarks nil) | ||
| 944 | |||
| 945 | (defun eww-add-bookmark () | ||
| 946 | "Add the current page to the bookmarks." | ||
| 947 | (interactive) | ||
| 948 | (eww-read-bookmarks) | ||
| 949 | (dolist (bookmark eww-bookmarks) | ||
| 950 | (when (equal eww-current-url | ||
| 951 | (plist-get bookmark :url)) | ||
| 952 | (error "Already bookmarked"))) | ||
| 953 | (push (list :url eww-current-url | ||
| 954 | :title eww-current-title | ||
| 955 | :time (current-time-string)) | ||
| 956 | eww-bookmarks) | ||
| 957 | (eww-write-bookmarks) | ||
| 958 | (message "Bookmarked %s (%s)" eww-current-url eww-current-title)) | ||
| 959 | |||
| 960 | (defun eww-write-bookmarks () | ||
| 961 | (with-temp-file (expand-file-name "eww-bookmarks" user-emacs-directory) | ||
| 962 | (insert ";; Auto-generated file; don't edit\n") | ||
| 963 | (pp eww-bookmarks (current-buffer)))) | ||
| 964 | |||
| 965 | (defun eww-read-bookmarks () | ||
| 966 | (with-temp-buffer | ||
| 967 | (insert-file-contents | ||
| 968 | (expand-file-name "eww-bookmarks" user-emacs-directory)) | ||
| 969 | (setq eww-bookmarks (read (current-buffer))))) | ||
| 970 | |||
| 971 | (defun eww-list-bookmarks () | ||
| 972 | "Display the bookmarks." | ||
| 973 | (interactive) | ||
| 974 | (eww-bookmark-prepare) | ||
| 975 | (pop-to-buffer "*eww bookmarks*")) | ||
| 976 | |||
| 977 | (defun eww-bookmark-prepare () | ||
| 978 | (eww-read-bookmarks) | ||
| 979 | (when (null eww-bookmarks) | ||
| 980 | (error "No bookmarks are defined")) | ||
| 981 | (set-buffer (get-buffer-create "*eww bookmarks*")) | ||
| 982 | (eww-bookmark-mode) | ||
| 983 | (let ((format "%-40s %s") | ||
| 984 | (inhibit-read-only t) | ||
| 985 | start url) | ||
| 986 | (erase-buffer) | ||
| 987 | (setq header-line-format (concat " " (format format "URL" "Title"))) | ||
| 988 | (dolist (bookmark eww-bookmarks) | ||
| 989 | (setq start (point)) | ||
| 990 | (setq url (plist-get bookmark :url)) | ||
| 991 | (when (> (length url) 40) | ||
| 992 | (setq url (substring url 0 40))) | ||
| 993 | (insert (format format url | ||
| 994 | (plist-get bookmark :title)) | ||
| 995 | "\n") | ||
| 996 | (put-text-property start (1+ start) 'eww-bookmark bookmark)) | ||
| 997 | (goto-char (point-min)))) | ||
| 998 | |||
| 999 | (defvar eww-bookmark-kill-ring nil) | ||
| 1000 | |||
| 1001 | (defun eww-bookmark-kill () | ||
| 1002 | "Kill the current bookmark." | ||
| 1003 | (interactive) | ||
| 1004 | (let* ((start (line-beginning-position)) | ||
| 1005 | (bookmark (get-text-property start 'eww-bookmark)) | ||
| 1006 | (inhibit-read-only t)) | ||
| 1007 | (unless bookmark | ||
| 1008 | (error "No bookmark on the current line")) | ||
| 1009 | (forward-line 1) | ||
| 1010 | (push (buffer-substring start (point)) eww-bookmark-kill-ring) | ||
| 1011 | (delete-region start (point)) | ||
| 1012 | (setq eww-bookmarks (delq bookmark eww-bookmarks)) | ||
| 1013 | (eww-write-bookmarks))) | ||
| 1014 | |||
| 1015 | (defun eww-bookmark-yank () | ||
| 1016 | "Yank a previously killed bookmark to the current line." | ||
| 1017 | (interactive) | ||
| 1018 | (unless eww-bookmark-kill-ring | ||
| 1019 | (error "No previously killed bookmark")) | ||
| 1020 | (beginning-of-line) | ||
| 1021 | (let ((inhibit-read-only t) | ||
| 1022 | (start (point)) | ||
| 1023 | bookmark) | ||
| 1024 | (insert (pop eww-bookmark-kill-ring)) | ||
| 1025 | (setq bookmark (get-text-property start 'eww-bookmark)) | ||
| 1026 | (if (= start (point-min)) | ||
| 1027 | (push bookmark eww-bookmarks) | ||
| 1028 | (let ((line (count-lines start (point)))) | ||
| 1029 | (setcdr (nthcdr (1- line) eww-bookmarks) | ||
| 1030 | (cons bookmark (nthcdr line eww-bookmarks))))) | ||
| 1031 | (eww-write-bookmarks))) | ||
| 1032 | |||
| 1033 | (defun eww-bookmark-quit () | ||
| 1034 | "Kill the current buffer." | ||
| 1035 | (interactive) | ||
| 1036 | (kill-buffer (current-buffer))) | ||
| 1037 | |||
| 1038 | (defun eww-bookmark-browse () | ||
| 1039 | "Browse the bookmark under point in eww." | ||
| 1040 | (interactive) | ||
| 1041 | (let ((bookmark (get-text-property (line-beginning-position) 'eww-bookmark))) | ||
| 1042 | (unless bookmark | ||
| 1043 | (error "No bookmark on the current line")) | ||
| 1044 | (delete-window) | ||
| 1045 | (eww (plist-get bookmark :url)))) | ||
| 1046 | |||
| 1047 | (defun eww-next-bookmark () | ||
| 1048 | "Go to the next bookmark in the list." | ||
| 1049 | (interactive) | ||
| 1050 | (let ((first nil) | ||
| 1051 | bookmark) | ||
| 1052 | (unless (get-buffer "*eww bookmarks*") | ||
| 1053 | (setq first t) | ||
| 1054 | (eww-bookmark-prepare)) | ||
| 1055 | (with-current-buffer (get-buffer "*eww bookmarks*") | ||
| 1056 | (when (and (not first) | ||
| 1057 | (not (eobp))) | ||
| 1058 | (forward-line 1)) | ||
| 1059 | (setq bookmark (get-text-property (line-beginning-position) | ||
| 1060 | 'eww-bookmark)) | ||
| 1061 | (unless bookmark | ||
| 1062 | (error "No next bookmark"))) | ||
| 1063 | (eww-browse-url (plist-get bookmark :url)))) | ||
| 1064 | |||
| 1065 | (defun eww-previous-bookmark () | ||
| 1066 | "Go to the previous bookmark in the list." | ||
| 1067 | (interactive) | ||
| 1068 | (let ((first nil) | ||
| 1069 | bookmark) | ||
| 1070 | (unless (get-buffer "*eww bookmarks*") | ||
| 1071 | (setq first t) | ||
| 1072 | (eww-bookmark-prepare)) | ||
| 1073 | (with-current-buffer (get-buffer "*eww bookmarks*") | ||
| 1074 | (if first | ||
| 1075 | (goto-char (point-max)) | ||
| 1076 | (beginning-of-line)) | ||
| 1077 | ;; On the final line. | ||
| 1078 | (when (eolp) | ||
| 1079 | (forward-line -1)) | ||
| 1080 | (if (bobp) | ||
| 1081 | (error "No previous bookmark") | ||
| 1082 | (forward-line -1)) | ||
| 1083 | (setq bookmark (get-text-property (line-beginning-position) | ||
| 1084 | 'eww-bookmark))) | ||
| 1085 | (eww-browse-url (plist-get bookmark :url)))) | ||
| 1086 | |||
| 1087 | (defvar eww-bookmark-mode-map | ||
| 1088 | (let ((map (make-sparse-keymap))) | ||
| 1089 | (suppress-keymap map) | ||
| 1090 | (define-key map "q" 'eww-bookmark-quit) | ||
| 1091 | (define-key map [(control k)] 'eww-bookmark-kill) | ||
| 1092 | (define-key map [(control y)] 'eww-bookmark-yank) | ||
| 1093 | (define-key map "\r" 'eww-bookmark-browse) | ||
| 1094 | map)) | ||
| 1095 | |||
| 1096 | (define-derived-mode eww-bookmark-mode nil "eww bookmarks" | ||
| 1097 | "Mode for listing bookmarks. | ||
| 1098 | |||
| 1099 | \\{eww-bookmark-mode-map}" | ||
| 1100 | (buffer-disable-undo) | ||
| 1101 | (setq buffer-read-only t | ||
| 1102 | truncate-lines t)) | ||
| 1103 | |||
| 932 | (provide 'eww) | 1104 | (provide 'eww) |
| 933 | 1105 | ||
| 934 | ;;; eww.el ends here | 1106 | ;;; eww.el ends here |
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 7b64b4cb3eb..43a14985ae2 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | * url-cookie.el: Implement a command and mode for displaying and | 3 | * url-cookie.el: Implement a command and mode for displaying and |
| 4 | editing cookies. | 4 | editing cookies. |
| 5 | (url-cookie-mode): Fix mode name. | ||
| 5 | 6 | ||
| 6 | 2013-06-21 Glenn Morris <rgm@gnu.org> | 7 | 2013-06-21 Glenn Morris <rgm@gnu.org> |
| 7 | 8 | ||
diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el index 3e543300b30..008203c90df 100644 --- a/lisp/url/url-cookie.el +++ b/lisp/url/url-cookie.el | |||
| @@ -427,9 +427,10 @@ to run the `url-cookie-setup-save-timer' function manually." | |||
| 427 | (suppress-keymap map) | 427 | (suppress-keymap map) |
| 428 | (define-key map "q" 'url-cookie-quit) | 428 | (define-key map "q" 'url-cookie-quit) |
| 429 | (define-key map [delete] 'url-cookie-delete) | 429 | (define-key map [delete] 'url-cookie-delete) |
| 430 | (define-key map [(control k)] 'url-cookie-delete) | ||
| 430 | map)) | 431 | map)) |
| 431 | 432 | ||
| 432 | (define-derived-mode url-cookie-mode nil "eww" | 433 | (define-derived-mode url-cookie-mode nil "URL Cookie" |
| 433 | "Mode for listing cookies. | 434 | "Mode for listing cookies. |
| 434 | 435 | ||
| 435 | \\{url-cookie-mode-map}" | 436 | \\{url-cookie-mode-map}" |