FUEL: Better help page caching and some fixes.

db4
Jose A. Ortega Ruiz 2009-01-04 01:50:13 +01:00
parent 992633dd32
commit 9832429b94
2 changed files with 54 additions and 31 deletions

View File

@ -58,7 +58,7 @@ GENERIC: fuel-pprint ( obj -- )
M: object fuel-pprint pprint ; inline
: fuel-maybe-scape ( ch -- seq )
dup "?#()[]'`" member? [ CHAR: \ swap 2array ] [ 1array ] if ;
dup "\"?#()[]'`" member? [ CHAR: \ swap 2array ] [ 1array ] if ;
M: word fuel-pprint
name>> V{ } clone [ fuel-maybe-scape append ] reduce >string write ;

View File

@ -50,10 +50,20 @@
(make-ring fuel-help-history-cache-size))) ; next
(defvar fuel-help--history (fuel-help--make-history))
(defvar fuel-help--cache (make-hash-table :weakness 'key))
(defsubst fuel-help--cache-get (name)
(gethash name fuel-help--cache))
(defsubst fuel-help--cache-insert (name str)
(puthash name str fuel-help--cache))
(defsubst fuel-help--cache-clear ()
(clrhash fuel-help--cache))
(defun fuel-help--history-push (term)
(when (and (car fuel-help--history)
(not (string= (caar fuel-help--history) (car term))))
(not (string= (car fuel-help--history) term)))
(ring-insert (nth 1 fuel-help--history) (car fuel-help--history)))
(setcar fuel-help--history term))
@ -69,6 +79,9 @@
(ring-insert (nth 2 fuel-help--history) (car fuel-help--history)))
(setcar fuel-help--history (ring-remove (nth 1 fuel-help--history) 0))))
(defun fuel-help--history-current-content ()
(fuel-help--cache-get (car fuel-help--history)))
;;; Fuel help buffer and internals:
@ -92,34 +105,43 @@
def)))
(defun fuel-help--word-help (&optional see word)
(let ((def (or word (fuel-help--read-word see))))
(when def
(let ((cmd `(:fuel* (,def ,(if see 'fuel-word-see 'fuel-word-help))
"fuel" t)))
(message "Looking up '%s' ..." def)
(let* ((ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(if (not res)
(message "No help for '%s'" def)
(fuel-help--insert-contents def res)))))))
(let* ((def (or word (fuel-help--read-word see)))
(cached (fuel-help--cache-get def)))
(if cached
(fuel-help--insert-contents def cached)
(when def
(let ((cmd `(:fuel* (,def ,(if see 'fuel-word-see 'fuel-word-help))
"fuel" t)))
(message "Looking up '%s' ..." def)
(let* ((ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(if (not res)
(message "No help for '%s'" def)
(fuel-help--insert-contents def res))))))))
(defun fuel-help--get-article (name label)
(message "Retrieving article ...")
(let* ((cmd `(:fuel* ((,name fuel-get-article)) "fuel" t))
(ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(fuel-help--insert-contents label res)
(message "")))
(let ((cached (fuel-help--cache-get name)))
(if cached
(fuel-help--insert-contents name cached)
(message "Retrieving article ...")
(let* ((cmd `(:fuel* ((,name fuel-get-article)) "fuel" t))
(ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(fuel-help--insert-contents name res)
(message "")))))
(defun fuel-help--get-vocab (name)
(message "Retrieving vocabulary help ...")
(let* ((cmd `(:fuel* ((,name fuel-vocab-help)) "fuel" (,name)))
(ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(if (not res)
(message "No help available for vocabulary %s" name)
(fuel-help--insert-contents label res)
(message ""))))
(let ((cached (fuel-help--cache-get name)))
(if cached
(fuel-help--insert-contents name cached)
(message "Retrieving vocabulary help ...")
(let* ((cmd `(:fuel* ((,name fuel-vocab-help)) "fuel" (,name)))
(ret (fuel-eval--send/wait cmd 2000))
(res (fuel-eval--retort-result ret)))
(if (not res)
(message "No help available for vocabulary %s" name)
(fuel-help--insert-contents name res)
(message ""))))))
(defun fuel-help--follow-link (label link type)
(let ((fuel-help-always-ask nil))
@ -137,9 +159,9 @@
(if (stringp art)
(insert art)
(fuel-markup--print art)
(fuel-markup--insert-newline))
(unless nopush
(fuel-help--history-push (cons def (buffer-string))))
(fuel-markup--insert-newline)
(fuel-help--cache-insert def (buffer-string)))
(unless nopush (fuel-help--history-push def))
(set-buffer-modified-p nil)
(fuel-popup--display)
(goto-char (point-min))
@ -166,7 +188,7 @@ buffer."
(fuel-help-always-ask nil))
(unless item
(error "No next page"))
(fuel-help--insert-contents (car item) (cdr item) t)))
(fuel-help--insert-contents item (fuel-help--cache-get item) t)))
(defun fuel-help-previous ()
"Go to next page in help browser."
@ -175,12 +197,13 @@ buffer."
(fuel-help-always-ask nil))
(unless item
(error "No previous page"))
(fuel-help--insert-contents (car item) (cdr item) t)))
(fuel-help--insert-contents item (fuel-help--cache-get item) t)))
(defun fuel-help-clean-history ()
"Clean up the help browser cache of visited pages."
(interactive)
(when (y-or-n-p "Clean browsing history? ")
(fuel-help--cache-clear)
(setq fuel-help--history (fuel-help--make-history)))
(message ""))