-
Notifications
You must be signed in to change notification settings - Fork 0
/
hackernews.elc
40 lines (34 loc) · 3.91 KB
/
hackernews.elc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
;ELC
;;; Compiled by shant@ultraio on Sat Sep 27 19:36:32 2014
;;; from file /home/shant/.emacs.d/hackernews.el
;;; in Emacs version 24.3.1
;;; with all optimizations.
;;; This file uses dynamic docstrings, first added in Emacs 19.29.
;;; This file does not contain utf-8 non-ASCII characters,
;;; and so can be loaded in Emacs versions earlier than 23.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(byte-code "\300\301!\210\300\302!\207" [require json url] 2)
#@34 The url to grab the list of news
(defvar hackernews-url "http://api.ihackernews.com/page" (#$ . 566))
#@35 The keymap to use with hackernews
(defvar hackernews-map (make-sparse-keymap) (#$ . 674))
(byte-code "\203 \301\302\303#\210\202 \301\304\305#\210\301\207" [hackernews-map define-key "g" hackernews "q" bury-buffer] 4)
#@31 The entry point of our client
(defalias 'hackernews #[nil "\300\301\302\217\207" [ex (byte-code "\301\302\303!!!\207" [hackernews-url hackernews-format-results hackernews-parse hackernews-retrieve] 4) (('error (byte-code "\301\302\303A@\"!\207" [ex message format "Bad news, bro: %s"] 4)))] 3 (#$ . 903) nil])
#@41 Insert clickable string inside a buffer
(defalias 'hackernews-create-link-in-buffer #[(title url) "\306\307!\306\310!\306\311!\211\211\fL\210) \211L\210)\211\312 L\210)\313J\314\315\316\317\320\321\322D\321D\321 D\321\nD\323\257F#\210\313J\324\315\316\325\320\321\326D\321D\321 D\321\nD\323\257F#\210\327\nJ\330\331\332J\333\334&c+\207" [#1=#:--cl-map-- #2=#:--cl-url-- #3=#:--cl-title-- #4=#:v title #5=#:v make-symbol "--title--" "--url--" "--map--" make-sparse-keymap define-key "" lambda (&rest --cl-rest--) (interactive "p") apply quote #[(#6=#:G79330 #7=#:G79331 #8=#:G79332 e) "\301J!\207" [#7# browse-url] 2] --cl-rest-- [down-mouse-1] (interactive "p") #[(#9=#:G79333 #10=#:G79334 #11=#:G79335 e) "\301J!\207" [#10# browse-url] 2] propertize face (:foreground "green") keymap mouse-face highlight url #12=#:v] 13 (#$ . 1221)])
#@111 Makes sure that string is at least n characters long, and
if it isn't, it adds SPACE-characters to the end
(defalias 'hackernews-space-fill #[(string n) "G W\203 \302P\211\202 \207" [string n " "] 3 (#$ . 2085)])
#@120 Render a single post to the current buffer
Add the post title as a link, and print the points and number of
comments.
(defalias 'hackernews-render-post #[(post) "\301\302\303\304\305\306\"A\"\307\"!\210\310\305\311\"A\305\312\"A\"\210\313\303\314\305\315\"A\"\316\317#c\210\301\320!\207" [post princ hackernews-space-fill format "[%s]" assoc points 6 hackernews-create-link-in-buffer title url propertize " (%d comments)" commentCount face (:foreground "gray") "\n"] 7 (#$ . 2314)])
#@42 Create the buffer to render all the info
(defalias 'hackernews-format-results #[(results) "r\306\307!q\210p\310 \210 \311\211\312\211\312\313 \210\314\315!\210+\211\316\307!\210\311\317!\210\320\321!\210\322\323\324\325\"A\"\326!\210+\207" [default-directory #1=#:old-dir buffer-read-only buffer-file-name buffer-undo-list inhibit-modification-hooks get-buffer-create "*hackernews*" kill-all-local-variables nil t erase-buffer run-hooks temp-buffer-setup-hook switch-to-buffer use-local-map princ "Your hacker News Emacs client\n\n" mapcar hackernews-render-post assoc items internal-temp-output-buffer-show inhibit-read-only #2=#:buf standard-output font-lock-mode hackernews-map results] 6 (#$ . 2808)])
(defalias 'hackernews-retrieve #[(url) "\303!\304\212\nq\210eb\210\305\306\307 \"\204 \310\311!\210\312\313\304\314#\210\315`d\"\316p!\210) *\207" [url json buffer url-retrieve-synchronously nil string-match "200 OK" buffer-string error "Problem connecting to the server" re-search-forward "^$" move buffer-substring-no-properties kill-buffer] 4])
(defalias 'hackernews-parse #[(contents) "\301!\207" [contents json-read-from-string] 2])
(provide 'hackernews)