[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/xkcd 296aa18259 47/82: Merge branch 'master' of https://gi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/xkcd 296aa18259 47/82: Merge branch 'master' of https://github.com/vibhavp/emacs-xkcd |
Date: |
Mon, 12 Dec 2022 21:59:53 -0500 (EST) |
branch: elpa/xkcd
commit 296aa18259df4c5422c568a75bab54f13cc156bc
Merge: ef6e51ade7 f2650dc392
Author: Raphaël Cauderlier <cauderlier@crans.org>
Commit: Raphaël Cauderlier <cauderlier@crans.org>
Merge branch 'master' of https://github.com/vibhavp/emacs-xkcd
Conflicts:
xkcd.el
---
README.md | 5 +----
xkcd.el | 56 +++++++++++++++++++++++++++++++++++++-------------------
2 files changed, 38 insertions(+), 23 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 86827c7163..21bebb0eaf 100644
--- a/xkcd.el
+++ b/xkcd.el
@@ -79,38 +79,60 @@ The return value is a string."
(goto-char (point-min))
(unless cached (re-search-forward "^$"))
(prog1
- (buffer-substring-no-properties (point) (point-max))
- (kill-buffer (current-buffer))))))
+ (buffer-substring-no-properties (+ (point) 1) (point-max))
+ (kill-buffer (current-buffer))))))
+(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 to NUM.png.
-If the file NUM.png arleady exists, do nothing"
+ "Download the image linked by URL to NUM. If NUM arleady exists, do nothing"
;;check if the cache directory exists
(unless (file-exists-p xkcd-cache-dir)
(make-directory xkcd-cache-dir))
- (let ((name (format "%s%d.png" xkcd-cache-dir num)))
- (unless (file-exists-p name)
- (url-copy-file url name))))
+ (let ((name (format "%s%s.%s" xkcd-cache-dir (number-to-string num)
+ (substring url (- (length url) 3)))))
+ (if (file-exists-p 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."
- (let ((name (format "%s%d.json" xkcd-cache-dir num))
- (file 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))))
-
(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 FILENAME is a gif"
+ (let ((image (create-image (format "%s%d.%s" xkcd-cache-dir
+ 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."
@@ -130,16 +152,12 @@ If the file NUM.png arleady exists, do nothing"
(img (cdr (assoc 'img json-assoc)))
(num (cdr (assoc 'num json-assoc)))
(safe-title (cdr (assoc 'safe_title json-assoc)))
- title)
+ title file)
(message "Getting comic...")
- (xkcd-download img num)
+ (setq file (xkcd-download img num))
(setq title (format "%d: %s" num safe-title))
(insert title "\n")
- (let ((start (point)))
- (insert-image (create-image
- (format "%s%d.png" xkcd-cache-dir num)
- 'png))
- (add-text-properties start (point) '(help-echo xkcd-alt)))
+ (xkcd-insert-image file num)
(if (eq xkcd-cur 0)
(setq xkcd-cur num))
(xkcd-cache-json num out)
- [nongnu] elpa/xkcd 2da77a12e2 29/82: Provide xkcd instead of emacs-xkcd, (continued)
- [nongnu] elpa/xkcd 2da77a12e2 29/82: Provide xkcd instead of emacs-xkcd, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd e8bb80c4a0 30/82: Make comments work with Melpa., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd b303669b33 39/82: Merge pull request #7 from rafoo/master, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd ef6e51ade7 43/82: Code simplification, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd f2650dc392 46/82: Retrieve correct substring, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 3304f05265 59/82: Autoload xkcd-handle-links., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 60de549e25 63/82: Merge pull request #10 from heikkil/master, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 0310d572b7 68/82: * images/screenshot.png: Add screenshot., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 74b0dfe926 78/82: Retain the quote style when printing messages, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 2c796bcd0f 81/82: Merge pull request #25 from skangas/prefer-https, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 296aa18259 47/82: Merge branch 'master' of https://github.com/vibhavp/emacs-xkcd,
ELPA Syncer <=
- [nongnu] elpa/xkcd c2be5c6a08 50/82: Merge pull request #8 from rafoo/master, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 9f77f0422f 64/82: Require browse-url for external-browser functions to work., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 6166a690b5 73/82: Add MELPA badge., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 91be72384e 61/82: Open current xkcd in external browser, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd e0b7938714 54/82: Add docs for xkcd-handle-links., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 7148c2c135 57/82: Add (require 'image) to supress build warnings., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 97235a9fbd 58/82: Add autoloads., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 763b73d6de 69/82: * README.md: Remove feature from customize table which is still to be added., ELPA Syncer, 2022/12/12