Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lexical binding #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions org-protocol-capture-html.el
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
;;; org-protocol-capture-html.el --- Capture HTML with org-protocol
;;; org-protocol-capture-html.el --- Capture HTML with org-protocol -*- lexical-binding: t -*-

;; URL: https://github.com/alphapapa/org-protocol-capture-html
;; Version: 0.1-pre
;; Package-Requires: ((emacs "24.4"))
;; Package-Requires: ((emacs "26.1"))

;;; Commentary:

Expand Down Expand Up @@ -46,6 +46,8 @@
You may want to increase this if you use a sub-heading in your capture template."
:group 'org-protocol-capture-html :type 'integer)

(defvar org-protocol-capture-html--current-template nil)

;;;; Test Pandoc

(defconst org-protocol-capture-html-pandoc-no-wrap-option nil
Expand Down Expand Up @@ -100,9 +102,8 @@ Pandoc, converting HTML to Org-mode."

(unless org-protocol-capture-html-pandoc-no-wrap-option
(org-protocol-capture-html--define-pandoc-wrap-const))

(let* ((template (or (plist-get data :template)
org-protocol-default-template-key))
(let* ((org-protocol-capture-html--current-template (or (plist-get data :template)
org-protocol-default-template-key))
(url (org-protocol-sanitize-uri (plist-get data :url)))
(type (if (string-match "^\\([a-z]+\\):" url)
(match-string 1 url)))
Expand Down Expand Up @@ -158,8 +159,8 @@ Pandoc, converting HTML to Org-mode."
(unless org-protocol-capture-html-pandoc-no-wrap-option
(org-protocol-capture-html--define-pandoc-wrap-const))

(let* ((template (or (plist-get data :template)
org-protocol-default-template-key))
(let* ((org-protocol-capture-html--current-template (or (plist-get data :template)
org-protocol-default-template-key))
(url (org-protocol-sanitize-uri (plist-get data :url)))
(type (if (string-match "^\\([a-z]+\\):" url)
(match-string 1 url)))
Expand Down Expand Up @@ -259,21 +260,19 @@ Returns list (HTML . TITLE)."
;; them to underlines instead of spaces, but this fixes it.
(replace-regexp-in-string (rx " ") " " s t t))

(with-no-warnings
;; Ignore warning about the dynamically scoped `template' variable.
(defun org-protocol-capture-html--do-capture ()
"Call `org-capture' and demote page headings in capture buffer."
(raise-frame)
(funcall 'org-capture nil template)

;; Demote page headings in capture buffer to below the
;; top-level Org heading
(save-excursion
(goto-char (point-min))
(re-search-forward (rx bol "*" (1+ space)) nil t) ; Skip 1st heading
(while (re-search-forward (rx bol "*" (1+ space)) nil t)
(dotimes (n org-protocol-capture-html-demote-times)
(org-demote-subtree))))))
(defun org-protocol-capture-html--do-capture ()
"Call `org-capture' and demote page headings in capture buffer."
(raise-frame)
(org-capture nil org-protocol-capture-html--current-template)

;; Demote page headings in capture buffer to below the
;; top-level Org heading
(save-excursion
(goto-char (point-min))
(re-search-forward (rx bol "*" (1+ space)) nil t) ; Skip 1st heading
(while (re-search-forward (rx bol "*" (1+ space)) nil t)
(dotimes (_n org-protocol-capture-html-demote-times)
(org-demote-subtree)))))

(provide 'org-protocol-capture-html)

Expand Down