[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/xkcd a565d632fd 41/82: Support gif and jpg image extension
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/xkcd a565d632fd 41/82: Support gif and jpg image extensions. |
Date: |
Mon, 12 Dec 2022 21:59:52 -0500 (EST) |
branch: elpa/xkcd
commit a565d632fd4b3f3787d200de79d521bff51f16fc
Author: Vibhav Pant <vibhavp@gmail.com>
Commit: Vibhav Pant <vibhavp@gmail.com>
Support gif and jpg image extensions.
---
README.md | 5 +----
xkcd.el | 45 ++++++++++++++++++++++++++++++++-------------
2 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 506433b19d..59c3b3167c 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ Clone this repository to a desired location, and add the
following snippet to yo
Files are cached by default to ~/.emacs.d/xkcd/. This can be changed by
changing `xkcd-cache-dir` in the group "xkcd". (customize-group xkcd)
-`xkcd-get-latest` loads up the latest xkcd.
+`xkcd` loads up the latest xkcd.
# Current keybindings:
| Keybinding | Use | Function |
|:----------:|:------------------------------:|:--------------:|
@@ -33,8 +33,5 @@ Files are cached by default to ~/.emacs.d/xkcd/. This can be
changed by changing
| `<right>` | Load next xkcd | (xkcd-next) |
| `<left>` | Load previous xkcd | (xkcd-prev) |
-#Bugs
-Some comics using a different image extension do not to load.
-
#TODO
Add support for custom faces.
diff --git a/xkcd.el b/xkcd.el
index 94963bf61c..08acf65c99 100644
--- a/xkcd.el
+++ b/xkcd.el
@@ -81,15 +81,27 @@ be located in xkcd-cache-dir"
(kill-buffer (current-buffer)))
json-string))
+(defun xkcd-get-image-type (url)
+ (let ((substr (substring url (- (length url) 3))))
+ (cond
+ ((string= substr "png")
+ 'png)
+ ((string= substr "jpg")
+ 'jpg)
+ (t 'gif))))
+
(defun xkcd-download (url num)
"Download the image linked by URL. If the file arleady exists, do nothing"
;;check if the cache directory exists
(if (not (file-exists-p xkcd-cache-dir))
(make-directory xkcd-cache-dir))
- (let ((name (concat xkcd-cache-dir (number-to-string num) ".png")))
+ (let ((name (concat xkcd-cache-dir (number-to-string num) "." (substring
+ url
+ (- (length url)
3)))))
(if (file-exists-p name)
- nil
- (url-copy-file url name))))
+ name
+ (url-copy-file url name))
+ name))
(defun xkcd-cache-json (num json-string)
"Save xkcd NUM's JSON-STRING to cache directory, and write xkcd-latest to a
file"
@@ -110,6 +122,19 @@ be located in xkcd-cache-dir"
(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"
+ (let ((image (create-image (concat xkcd-cache-dir
+ (number-to-string num)
+ "."
+ (substring file (- (length file) 3)))
+ (xkcd-get-image-type file)))
+ (start (point)))
+ (insert-image image)
+ (if (image-multi-frame-p image)
+ (image-animate image 0 t))
+ (add-text-properties start (point) '(help-echo xkcd-alt))))
+
;;;###autoload
(defun xkcd-get (num)
"Get the xkcd number NUM"
@@ -129,24 +154,18 @@ be located in xkcd-cache-dir"
"/info.0.json") num)))
(img nil)
(num nil)
- (title nil))
+ (title nil)
+ (file nil))
(setq num (cdr (assoc 'num (json-read-from-string out))))
(setq img (cdr (assoc 'img (json-read-from-string out))))
;; FIXME: This looks pretty ugly.
(message "Getting comic...")
- (xkcd-download img num)
+ (setq file (xkcd-download img num))
(setq title (format "%d: %s" (cdr (assoc 'num (json-read-from-string out)))
(cdr (assoc 'safe_title (json-read-from-string out)))))
(insert (concat title "\n"))
- (let ((start (point)))
- (insert-image (create-image
- (concat xkcd-cache-dir
- (number-to-string
- (cdr
- (assoc 'num (json-read-from-string out))))
".png") 'png))
- (add-text-properties start (point) '(help-echo xkcd-alt))
- )
+ (xkcd-insert-image file num)
(if (eq xkcd-cur 0)
(setq xkcd-cur (cdr (assoc 'num (json-read-from-string out)))))
(xkcd-cache-json num out)
- [nongnu] elpa/xkcd 0f1abaebf5 14/82: typo: keybinding is t not r, (continued)
- [nongnu] elpa/xkcd 0f1abaebf5 14/82: typo: keybinding is t not r, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd f7b5157cdd 03/82: * README.md: Fix directory path, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 7ceb6cfb46 04/82: Update README.md, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 3acd31542b 06/82: Fix up search in xkcd-get-json. Add new line to README.md., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 3a1d89e234 07/82: Add screenshot, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd ef2ae149e6 10/82: Add TODO to docs., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 637f3d546e 15/82: Merge pull request #1 from oylenshpeegul/patch-1, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 51a00504a1 19/82: Release Version 1.0, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd b409d07459 24/82: Add travis support., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd b88b3df8b2 27/82: Update to reflect rename., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd a565d632fd 41/82: Support gif and jpg image extensions.,
ELPA Syncer <=
- [nongnu] elpa/xkcd 11c428c1b7 17/82: Fix xkcd-rand., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 26954c3cfc 48/82: Use image-animated-p instead of image-multi-frame-p for Emacs < 24.4, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 311abf717c 20/82: Add autoload cookie for main entry point, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 746acbab54 23/82: Add .travis.yml., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 775a194d77 26/82: Screenshot should show the alt-text capabilities., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 0911bd3f5c 32/82: json 1.4 not strictly required. Fixes #5., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 86acb5dcb2 55/82: Fix typo in variable name., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 502a36d15e 38/82: Add `xkcd' as an alias for `xkcd-get-latest', ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 6338b49627 40/82: Use major mode instead of minor mode, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd c13dacaf70 56/82: Correct table., ELPA Syncer, 2022/12/12