Skip to content

Commit 3359ce9

Browse files
committed
Tidy: Warnings, requirements, headers, strings
Closes #5. Thanks to @syohex for originally reporting these issues.
1 parent 23a1336 commit 3359ce9

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

org-protocol-capture-html.el

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
;;; org-protocol-capture-html.el --- Capture HTML with org-protocol
22

3+
;; URL: https://github.com/alphapapa/org-protocol-capture-html
4+
;; Version: 0.1-pre
5+
;; Package-Requires: ((emacs "24.4"))
6+
37
;;; Commentary:
48

59
;; This package captures Web pages into Org-mode using Pandoc to
@@ -31,7 +35,7 @@
3135
;;;; Require
3236

3337
(require 'org-protocol)
34-
(require 'cl)
38+
(require 'cl-lib)
3539
(require 'subr-x)
3640
(require 's)
3741

@@ -46,8 +50,9 @@ You may want to increase this if you use a sub-heading in your capture template.
4650

4751
(defconst org-protocol-capture-html-pandoc-no-wrap-option nil
4852
;; Set this so it won't be unbound
49-
"Option to pass to Pandoc to disable wrapping. Pandoc >= 1.16
50-
deprecates `--no-wrap' in favor of `--wrap=none'.")
53+
"Option to pass to Pandoc to disable wrapping.
54+
Pandoc >= 1.16 deprecates `--no-wrap' in favor of
55+
`--wrap=none'.")
5156

5257
(defun org-protocol-capture-html--define-pandoc-wrap-const ()
5358
"Set `org-protocol-capture-html-pandoc-no-wrap-option'."
@@ -81,7 +86,7 @@ deprecates `--no-wrap' in favor of `--wrap=none'.")
8186
;;;; Direct-to-Pandoc
8287

8388
(defun org-protocol-capture-html--with-pandoc (data)
84-
"Process an org-protocol://capture-html:// URL.
89+
"Process an org-protocol://capture-html:// URL using DATA.
8590
8691
This function is basically a copy of `org-protocol-do-capture', but
8792
it passes the captured content (not the URL or title) through
@@ -136,6 +141,8 @@ Pandoc, converting HTML to Org-mode."
136141

137142
;;;; eww-readable
138143

144+
(defvar url-http-end-of-headers)
145+
139146
(eval-when-compile
140147
;; eww-readable only works on Emacs >=25.1, but I think it's better
141148
;; to check for the actual symbols. I think using
@@ -165,7 +172,7 @@ Pandoc, converting HTML to Org-mode."
165172
(unless (= 0 (call-process-region (point-min) (point-max)
166173
"pandoc" t t nil "-f" "html" "-t" "org"
167174
org-protocol-capture-html-pandoc-no-wrap-option))
168-
(error "Pandoc failed."))
175+
(error "Pandoc failed"))
169176
(save-excursion
170177
;; Remove DOS CR/LF line endings
171178
(goto-char (point-min))
@@ -237,7 +244,7 @@ Returns list (HTML . TITLE)."
237244
(dom (with-temp-buffer
238245
(insert html)
239246
(libxml-parse-html-region (point-min) (point-max))))
240-
(title (caddr (car (dom-by-tag dom 'title)))))
247+
(title (cl-caddr (car (dom-by-tag dom 'title)))))
241248
(eww-score-readability dom)
242249
(cons (with-temp-buffer
243250
(shr-dom-print (eww-highest-readability dom))
@@ -252,20 +259,22 @@ Returns list (HTML . TITLE)."
252259
;; them to underlines instead of spaces, but this fixes it.
253260
(replace-regexp-in-string (rx " ") " " s t t))
254261

255-
(defun org-protocol-capture-html--do-capture ()
256-
"Call `org-capture' and demote page headings in capture buffer."
257-
(raise-frame)
258-
(funcall 'org-capture nil template)
259-
260-
;; Demote page headings in capture buffer to below the
261-
;; top-level Org heading
262-
(save-excursion
263-
(goto-char (point-min))
264-
(re-search-forward (rx bol "*" (1+ space)) nil t) ; Skip 1st heading
265-
(while (re-search-forward (rx bol "*" (1+ space)) nil t)
266-
(dotimes (n org-protocol-capture-html-demote-times)
267-
(org-demote-subtree)))))
262+
(with-no-warnings
263+
;; Ignore warning about the dynamically scoped `template' variable.
264+
(defun org-protocol-capture-html--do-capture ()
265+
"Call `org-capture' and demote page headings in capture buffer."
266+
(raise-frame)
267+
(funcall 'org-capture nil template)
268+
269+
;; Demote page headings in capture buffer to below the
270+
;; top-level Org heading
271+
(save-excursion
272+
(goto-char (point-min))
273+
(re-search-forward (rx bol "*" (1+ space)) nil t) ; Skip 1st heading
274+
(while (re-search-forward (rx bol "*" (1+ space)) nil t)
275+
(dotimes (n org-protocol-capture-html-demote-times)
276+
(org-demote-subtree))))))
268277

269278
(provide 'org-protocol-capture-html)
270279

271-
;;; org-protocol-capture-html ends here
280+
;;; org-protocol-capture-html.el ends here

0 commit comments

Comments
 (0)