From 4f6426bd40c2855f512a3ebecf0d9af3085777c4 Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Sun, 4 Jan 2009 04:04:08 +0100 Subject: [PATCH] FUEL: Help page bookmarks facility. --- misc/fuel/README | 5 +++- misc/fuel/fuel-help.el | 56 +++++++++++++++++++++++++++++++++++----- misc/fuel/fuel-markup.el | 13 +++++++--- 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/misc/fuel/README b/misc/fuel/README index 558078b9f8..530047006f 100644 --- a/misc/fuel/README +++ b/misc/fuel/README @@ -98,7 +98,10 @@ C-cC-eC-r is the same as C-cC-er)). - h : help for word at point - a : find words containing given substring (M-x fuel-apropos) - - f/b : next/previous page + - ba : bookmark current page + - bb : display bookmarks + - bd : delete bookmark at point + - n/p : next/previous page - SPC/S-SPC : scroll up/down - TAB/S-TAB : next/previous link - c : clean browsing history diff --git a/misc/fuel/fuel-help.el b/misc/fuel/fuel-help.el index 1eaf0235f1..da6d272d68 100644 --- a/misc/fuel/fuel-help.el +++ b/misc/fuel/fuel-help.el @@ -42,6 +42,10 @@ :type 'integer :group 'fuel-help) +(defcustom fuel-help-bookmarks nil + "Bookmars. Maintain this list using the help browser." + :type 'list + :group 'fuel-help) ;;; Help browser history: @@ -68,6 +72,9 @@ (ring-insert (nth 1 fuel-help--history) (car fuel-help--history))) (setcar fuel-help--history term)) +(defsubst fuel-help--history-current () + (car fuel-help--history)) + (defun fuel-help--history-next () (when (not (ring-empty-p (nth 2 fuel-help--history))) (when (car fuel-help--history) @@ -92,6 +99,9 @@ (defvar fuel-help--prompt-history nil) +(make-local-variable + (defvar fuel-help--buffer-link nil)) + (defun fuel-help--read-word (see) (let* ((def (fuel-syntax-symbol-at-point)) (prompt (format "See%s help on%s: " (if see " short" "") @@ -118,7 +128,8 @@ (res (fuel-eval--retort-result ret))) (if (not res) (message "No help for '%s'" def) - (fuel-help--insert-contents def res)))))))) + (fuel-help--insert-contents def res)))))) + (setq fuel-help--buffer-link (list def def 'word)))) (defun fuel-help--get-article (name label) (let ((cached (fuel-help--cache-get name))) @@ -129,7 +140,8 @@ (ret (fuel-eval--send/wait cmd 2000)) (res (fuel-eval--retort-result ret))) (fuel-help--insert-contents name res) - (message ""))))) + (message ""))) + (setq fuel-help--buffer-link (list name label 'article)))) (defun fuel-help--get-vocab (name) (let ((cached (fuel-help--cache-get name))) @@ -142,7 +154,8 @@ (if (not res) (message "No help available for vocabulary %s" name) (fuel-help--insert-contents name res) - (message "")))))) + (message "")))) + (setq fuel-help--buffer-link (list name name 'vocab)))) (defun fuel-help--follow-link (label link type) (let ((fuel-help-always-ask nil)) @@ -161,7 +174,7 @@ (insert art) (fuel-markup--print art) (fuel-markup--insert-newline) - (fuel-help--cache-insert def (buffer-string))) + (when def (fuel-help--cache-insert def (buffer-string)))) (unless nopush (fuel-help--history-push def)) (set-buffer-modified-p nil) (fuel-popup--display) @@ -169,6 +182,36 @@ (message ""))) +;;; Bookmarks: + +(defun fuel-help-bookmark-page () + "Add current help page to bookmarks." + (interactive) + (let ((link fuel-help--buffer-link)) + (unless link (error "No link associated to this page")) + (add-to-list 'fuel-help-bookmarks link) + (customize-save-variable 'fuel-help-bookmarks fuel-help-bookmarks) + (message "Bookmark '%s' saved" (cadr link)))) + +(defun fuel-help-delete-bookmark () + "Delete link at point from bookmarks." + (interactive) + (let ((link (fuel-markup--link-at-point))) + (unless link (error "No link at point")) + (unless (member link fuel-help-bookmarks) + (error "'%s' is not bookmarked" (cadr link))) + (customize-save-variable 'fuel-help-bookmarks + (remove link fuel-help-bookmarks)) + (message "Bookmark '%s' delete" (cadr link)) + (fuel-help-display-bookmarks))) + +(defun fuel-help-display-bookmarks () + "Display bookmarked pages." + (interactive) + (let ((links (mapcar (lambda (l) (cons '$subsection l)) fuel-help-bookmarks))) + (unless links (error "No links to display")) + (fuel-help--insert-contents nil (list 'article "Bookmarks" links) t))) + ;;; Interactive help commands: (defun fuel-help-short () @@ -216,9 +259,10 @@ buffer." (suppress-keymap map) (set-keymap-parent map button-buffer-map) (define-key map "a" 'fuel-apropos) - (define-key map "b" 'fuel-help-previous) + (define-key map "ba" 'fuel-help-bookmark-page) + (define-key map "bb" 'fuel-help-display-bookmarks) + (define-key map "bd" 'fuel-help-delete-bookmark) (define-key map "c" 'fuel-help-clean-history) - (define-key map "f" 'fuel-help-next) (define-key map "h" 'fuel-help) (define-key map "l" 'fuel-help-previous) (define-key map "p" 'fuel-help-previous) diff --git a/misc/fuel/fuel-markup.el b/misc/fuel/fuel-markup.el index 9896c4a934..fa6e26b3dd 100644 --- a/misc/fuel/fuel-markup.el +++ b/misc/fuel/fuel-markup.el @@ -72,6 +72,13 @@ (fuel-eval--retort-result (fuel-eval--send/wait `(:fuel* ((,name fuel-article-title :get)) "fuel")))) +(defun fuel-markup--link-at-point () + (let ((button (condition-case nil (forward-button 0) (error nil)))) + (when button + (list (button-get button 'markup-link) + (button-label button) + (button-get button 'markup-link-type))))) + ;;; Markup printers: @@ -259,9 +266,9 @@ (fuel-markup--print (cons '$code (cdr e)))) (defun fuel-markup--link (e) - (let* ((link (cadr e)) - (type (if (symbolp link) 'word 'article)) - (label (or (car (cddr e)) + (let* ((link (nth 1 e)) + (type (or (nth 3 e) (if (symbolp link) 'word 'article))) + (label (or (nth 2 e) (and (eq type 'article) (fuel-markup--article-title link)) link)))