Commit bceae8d014bd
Changed files (1)
.emacs.d
.emacs.d/emacs.org
@@ -1759,6 +1759,79 @@
("sbr" :components ("sbr-notes" "sbr-static"))
))
#+END_SRC
+*** Protocol
+
+ Trying out org-protocol based on
+ http://oremacs.com/2015/01/07/org-protocol-1/ and
+ http://oremacs.com/2015/01/08/org-protocol-2/.
+
+
+ #+BEGIN_SRC emacs-lisp
+ (use-package org-capture)
+ (use-package org-protocol)
+ (use-package async
+ :ensure t)
+ (setq org-protocol-default-template-key "l")
+ (push '("l" "Link" entry (function org-handle-link)
+ "* TODO %(org-wash-link)\nAdded: %U\n%(org-link-hooks)\n%?")
+ org-capture-templates)
+
+ (defun org-wash-link ()
+ (let ((link (caar org-stored-links))
+ (title (cadar org-stored-links)))
+ (setq title (replace-regexp-in-string
+ " - Stack Overflow" "" title))
+ (org-make-link-string link title)))
+
+ (defvar org-link-hook nil)
+
+ (defun org-link-hooks ()
+ (prog1
+ (mapconcat #'funcall
+ org-link-hook
+ "\n")
+ (setq org-link-hook)))
+
+ (defun org-handle-link ()
+ (let ((link (caar org-stored-links))
+ file)
+ (cond ((string-match "^https://www.youtube.com/" link)
+ (org-handle-link-youtube link))
+ ((string-match (regexp-quote
+ "http://stackoverflow.com/") link)
+ (find-file ("~/desktop/org/notes/stack.org"))
+ (goto-char (point-min))
+ (re-search-forward "^\\*+ +Questions" nil t))
+ (t
+ (find-file ("~/desktop/org/notes/ent.org"))
+ (goto-char (point-min))
+ (re-search-forward "^\\*+ +Articles" nil t)))))
+
+ (defun org-handle-link-youtube (link)
+ (lexical-let*
+ ((file-name (org-trim
+ (shell-command-to-string
+ (concat
+ "youtube-dl \""
+ link
+ "\""
+ " -o \"%(title)s.%(ext)s\" --get-filename"))))
+ (dir "~/desktop/videos/")
+ (full-name
+ (expand-file-name file-name dir)))
+ (add-hook 'org-link-hook
+ (lambda ()
+ (concat
+ (org-make-link-string dir dir)
+ "\n"
+ (org-make-link-string full-name file-name))))
+ (async-shell-command
+ (format "youtube-dl \"%s\" -o \"%s\"" link full-name))
+ (find-file (org-expand "ent.org"))
+ (goto-char (point-min))
+ (re-search-forward "^\\*+ +videos" nil t)))
+ #+END_SRC
+
** Projectile
#+BEGIN_QUOTE