summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/servall-client.el7
-rw-r--r--lisp/servall-wikipedia.el55
2 files changed, 40 insertions, 22 deletions
diff --git a/lisp/servall-client.el b/lisp/servall-client.el
index 2c6dd17..80376e7 100644
--- a/lisp/servall-client.el
+++ b/lisp/servall-client.el
@@ -40,11 +40,14 @@
(call-interactively 'delete-trailing-whitespace)
(if (string= status "200")
(unless (= (point) (point-max))
+ (setq json (json-read-from-string
+ (decode-coding-string
+ (buffer-string) 'utf-8)))
(if with-header
(list
(cons 'header fields)
- (cons 'json (json-read)))
- (json-read)))
+ (cons 'json json))
+ json))
(error "HTTP error: %s" (buffer-substring (point) (point-max)))))))
(provide 'servall-client)
diff --git a/lisp/servall-wikipedia.el b/lisp/servall-wikipedia.el
index ff2fb3a..309381b 100644
--- a/lisp/servall-wikipedia.el
+++ b/lisp/servall-wikipedia.el
@@ -1,6 +1,15 @@
;; -*- lexical-binding: t; -*-
-
-(defvar servall-results-mode-map special-mode-map)
+(require 'servall-client)
+
+(defvar servall-results-mode-map
+ (let ((map (make-sparse-keymap)))
+ (setq map (copy-keymap special-mode-map))
+ (define-key map "n" 'org-next-visible-heading)
+ (define-key map "g" 'servall-results-update)
+ (define-key map "\r" 'servall-results-open)
+ (define-key map "p" 'org-previous-visible-heading)
+ (define-key map "s" 'servall-results-re-search)
+ map))
(defvar servall-results-buffer "*servall-results*")
(define-derived-mode servall-results-mode org-mode "servall-results"
@@ -22,11 +31,6 @@
(interactive)
(funcall servall-results-open-function))
-(define-key servall-results-mode-map "n" 'org-next-visible-heading)
-(define-key servall-results-mode-map "g" 'servall-results-update)
-(define-key servall-results-mode-map "\r" 'servall-results-open)
-(define-key servall-results-mode-map "p" 'org-previous-visible-heading)
-(define-key servall-results-mode-map "s" 'servall-results-re-search)
(define-derived-mode servall-wikipedia-results-mode servall-results-mode
"servall-wikipedia-results"
@@ -76,28 +80,39 @@
(defun servall-wikipedia-to-name (title)
(replace-regexp-in-string " " "_" title))
-(defvar servall-wikipedia-view-mode-map special-mode-map)
+(defvar servall-wikipedia-view-mode-map
+ (let ((map (make-sparse-keymap)))
+ (setq map (copy-keymap special-mode-map))
+ (define-key map "g" 'servall-wikipedia-reload)
+ (define-key map "n" 'org-next-visible-heading)
+ (define-key map "p" 'org-previous-visible-heading)
+ map))
(defun servall-wikipedia-view-buffer (title)
(format "*wikipedia %s*" title))
-(defvar servall-wikipedia-view-mode-map special-mode-map)
-
-;; TOOD: fix view mode inheriting key bindings from results mode
(define-derived-mode servall-wikipedia-view-mode org-mode
"servall-wikipedia-view"
"Mode for viewing wikipedia entries."
(setq-local buffer-read-only t
servall-wikipedia-title nil))
-(defun servall-wikipedia-load (title)
- (let ((buffer (get-buffer-create (servall-wikipedia-view-buffer title))))
- (with-current-buffer buffer
- (servall-wikipedia-view-mode)
- (setq servall-wikipedia-title title)
- (let ((inhibit-read-only t))
- (erase-buffer)
- (insert (servall-api-wikipedia-org title)))
- (goto-char (point-min)))
+(defun servall-wikipedia-reload ()
+ (interactive)
+ (servall-wikipedia-load servall-wikipedia-title t))
+
+(defun servall-wikipedia-load (title &optional force)
+ (let* ((buffer-name (servall-wikipedia-view-buffer title))
+ (buffer (get-buffer buffer-name)))
+ (unless (and buffer (not force))
+ (setq buffer (get-buffer-create buffer-name))
+ (with-current-buffer buffer
+ (servall-wikipedia-view-mode)
+ (setq servall-wikipedia-title title)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert "* " title "\n")
+ (insert (servall-api-wikipedia-org title)))
+ (goto-char (point-min))))
buffer))
(provide 'servall-wikipedia)