[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/xkcd e04bb9535d 44/82: Incorporate some changes from rafoo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/xkcd e04bb9535d 44/82: Incorporate some changes from rafoo's branch. |
Date: |
Mon, 12 Dec 2022 21:59:52 -0500 (EST) |
branch: elpa/xkcd
commit e04bb9535d8eabb581aa04a31b64780879e31fed
Author: Vibhav Pant <vibhavp@inspiron-1150.lan>
Commit: Vibhav Pant <vibhavp@inspiron-1150.lan>
Incorporate some changes from rafoo's branch.
---
xkcd.el | 66 ++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 33 insertions(+), 33 deletions(-)
diff --git a/xkcd.el b/xkcd.el
index 08acf65c99..50650be2dc 100644
--- a/xkcd.el
+++ b/xkcd.el
@@ -37,24 +37,23 @@
(require 'url)
;;;###autoload
-(define-minor-mode xkcd-mode
- "Minor mode for viewing xkcd in Emacs"
- :lighter " xkcd"
- :global nil
- :keymap (let ((map (make-sparse-keymap)))
- (define-key map (kbd "<right>") 'xkcd-next)
- (define-key map (kbd "<left>") 'xkcd-prev)
- (define-key map (kbd "r") 'xkcd-rand)
- (define-key map (kbd "t") 'xkcd-alt-text)
- (define-key map (kbd "q") 'xkcd-kill-buffer)
- map))
+(define-derived-mode xkcd-mode special-mode "xkcd"
+ "Major mode for viewing xkcd (http://xkcd.com/) comics."
+ :group 'xkcd)
+
+(define-key xkcd-mode-map (kbd "<right>") 'xkcd-next)
+(define-key xkcd-mode-map (kbd "<left>") 'xkcd-prev)
+(define-key xkcd-mode-map (kbd "r") 'xkcd-rand)
+(define-key xkcd-mode-map (kbd "t") 'xkcd-alt-text)
+(define-key xkcd-mode-map (kbd "q") 'xkcd-kill-buffer)
(defvar xkcd-alt nil)
(defvar xkcd-cur nil)
(defvar xkcd-latest 0)
(defgroup xkcd nil
- "A xkcd reader for Emacs")
+ "A xkcd reader for Emacs"
+ :group 'multimedia)
(defcustom xkcd-cache-dir "~/.emacs.d/xkcd/"
"Directory to cache images and json files to."
@@ -68,18 +67,20 @@ be located in xkcd-cache-dir"
:type 'file)
(defun xkcd-get-json (url &optional num)
- (let ((json-string nil)
- (file (concat xkcd-cache-dir (number-to-string num) ".json")))
- (with-current-buffer (if (and (file-exists-p file) (not (eq num 0)))
+ "Fetch the Json coming from URL.
+If the file NUM.json exists, use it instead.
+If NUM is 0, always download from URL.
+The return value is a string."
+ (let* ((file (format "%s%d.json" xkcd-cache-dir num))
+ (cached (and (file-exists-p file) (not (eq num 0)))))
+ (with-current-buffer (if cached
(find-file file)
- (url-retrieve-synchronously url))
- (goto-char (point-min))
- (if (not (and (file-exists-p file) (not (eq num 0))))
- (re-search-forward "^$")
- (goto-char (point-min)))
- (setq json-string (buffer-substring-no-properties (point) (point-max)))
- (kill-buffer (current-buffer)))
- json-string))
+ (url-retrieve-synchronously url)))
+ (goto-char (point-min))
+ (unless cached (re-search-forward "^$"))
+ (prog1
+ (buffer-substring-no-properties (point) (point-min))
+ (kill-buffer (current-buffer)))))
(defun xkcd-get-image-type (url)
(let ((substr (substring url (- (length url) 3))))
@@ -91,10 +92,9 @@ be located in xkcd-cache-dir"
(t 'gif))))
(defun xkcd-download (url num)
- "Download the image linked by URL. If the file arleady exists, do nothing"
+ "Download the image linked by URL to NUM. If NUM arleady exists, do nothing"
;;check if the cache directory exists
- (if (not (file-exists-p xkcd-cache-dir))
- (make-directory xkcd-cache-dir))
+ (unless (file-exists-p xkcd-cache-dir) (make-directory xkcd-cache-dir))
(let ((name (concat xkcd-cache-dir (number-to-string num) "." (substring
url
(- (length url)
3)))))
@@ -104,26 +104,26 @@ be located in xkcd-cache-dir"
name))
(defun xkcd-cache-json (num json-string)
- "Save xkcd NUM's JSON-STRING to cache directory, and write xkcd-latest to a
file"
- (let ((name (concat xkcd-cache-dir (number-to-string num) ".json"))
- (file (concat xkcd-cache-latest)))
+ "Save xkcd NUM's JSON-STRING to cache directory,
+and write xkcd-latest to a file"
+ (let ((name (format "%s%d.json" xkcd-cache-dir num)))
(if (> num xkcd-latest)
- (with-current-buffer (find-file file)
+ (with-current-buffer (find-file xkcd-cache-latest)
(setq xkcd-latest num)
(erase-buffer)
(insert (number-to-string num))
(save-buffer)
(kill-buffer (current-buffer))))
- (if (file-exists-p name)
- nil
+ (unless (file-exists-p (name))
(with-current-buffer (find-file name)
(insert json-string)
(save-buffer)
(kill-buffer (current-buffer))))))
(defun xkcd-insert-image (file num)
- "Insert image FILENAME in buffer with the title-text, and animate if
necessary"
+ "Insert image FILENAME in buffer with the title-text,
+and animate if FILENAME is a gif"
(let ((image (create-image (concat xkcd-cache-dir
(number-to-string num)
"."
- [nongnu] elpa/xkcd 66eceb7896 62/82: Remove xkcd-handle-urls and friends., (continued)
- [nongnu] elpa/xkcd 66eceb7896 62/82: Remove xkcd-handle-urls and friends., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd f539b436cc 60/82: Remove xkcd-handle-link parts to prevent links from being broken., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd f940c7646a 74/82: Add line between MELPA badge and text., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 20e24f1c9b 70/82: Code block is in emacs-lisp, fix directories., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 8f0009f159 77/82: Merge pull request #16 from kaushalmodi/next-prev-args-and-copy-link, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 4845ef86f1 76/82: Add prefix arg to next/prev fn, add copy-link fn, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 2c538d41a9 79/82: Merge pull request #18 from kaushalmodi/retain-quote-style-in-messages, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd b9a3dfa150 33/82: Add docstring for xkcd-alt-text., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 4d280972bc 35/82: Add (xkcd-update-latest) to xkcd-get., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd b966b340b4 22/82: Rename to xkcd.el, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd e04bb9535d 44/82: Incorporate some changes from rafoo's branch.,
ELPA Syncer <=
- [nongnu] elpa/xkcd 57659266fa 65/82: Fix jpg viewing issue., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd a55c3f7dcd 75/82: Add faces to comic title., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 80011da2e7 82/82: Update copyright years., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd ca3eed5603 80/82: Prefer HTTPS to HTTP, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 5c10f6a679 21/82: Merge pull request #4 from purcell/patch-1, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 25594f98c7 31/82: Add info about Melpa in README., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 52c0d270de 36/82: Use one-letter keybindings, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 20e0b48044 42/82: Correct flycheck warnings, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd f5942003bf 45/82: Fix xkcd-get-json, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 3c13ae29c4 49/82: Docstrings, ELPA Syncer, 2022/12/12