Posts tagged "snippets":
<2019-06-14 Fri>
Tag elements if there are any unread emails in your mu4e
inbox.
(defconst ragone-unread-tag "unread" "Tag to add to Org elements which have unread emails.") (defun ragone-tag-unread-elements () "Update Org elements with `ragone-unread-tag' if there are unread emails." (unless (mu4e~proc-running-p) (mu4e~proc-start)) (org-map-entries (lambda () (let* ((search (concat "flag:unread " (nth 4 (org-heading-components)))) (code (with-temp-buffer (call-process "mu" nil (current-buffer) nil "find" search)))) (org-toggle-tag ragone-unread-tag (if (= 0 code) 'on 'off)))) t 'agenda)) ;; Add a hook to run before agenda displays. (add-hook 'org-agenda-mode-hook #'ragone-tag-unread-elements)
<2019-05-26 Sun>
My initial buffer displays a random quote from a list of programming/CS quotes. The complete list of quotes can be found here.
(defvar ragone-quotes-file "~/.doom.d/quotes.txt" "File to lookup quotes.") (defvar ragone-quotes-file-seperator-regex "\n%\n" "Delimiter for seperating the line in `ragone-quotes-file'.") (defvar ragone-quotes-author-regex "^--" "Regex for getting the author of the quote. Anything after this will be changed to face `font-lock-comment-face'.") (defun ragone-get-quote (&optional nth) "Get a random quote from `ragone-quotes-file'. Optionally get the NTH quote." (let* ((quotes (split-string (with-temp-buffer (insert-file-contents ragone-quotes-file) (buffer-substring-no-properties (point-min) (point-max))) ragone-quotes-file-seperator-regex t)) (selected-quote (nth (or nth (random (length quotes))) quotes))) (put-text-property (string-match ragone-quotes-author-regex selected-quote) (length selected-quote) 'face 'font-lock-comment-face selected-quote) selected-quote)) ;; Update your scratch buffer (setq initial-scratch-message (ragone-get-quote))
<2019-05-23 Thu>
Quickly copy an image of a htmlized buffer or region to the clipboard.
(defun ragone-htmlize () "Convert the htmlized region to an image and copy to clipboard." (interactive) (let ((htmlize-pre-style t) (region-background (face-attribute 'region :background)) (start (if (region-active-p) (region-beginning) (point-min))) (end (if (region-active-p) (region-end) (point-max)))) (set-face-background 'region "unspecified") (unwind-protect (ragone-htmlize-to-clipboard (htmlize-region-for-paste start end)) (set-face-background 'region region-background)))) (defun ragone-htmlize-to-clipboard (html) "Copy HTML to clipboard." (with-temp-buffer (insert html) (call-shell-region (point-min) (point-max) "wkhtmltoimage -f png - - | xclip -i -selection clipboard -t image/png")))
<2019-05-11 Sat>
Easily toggle between your notes and your working buffer.
(defun ragone-kill-deft-buffers () "Toggle Deft mode." (interactive) (save-excursion (let ((count 0)) (dolist (buffer (buffer-list)) (set-buffer buffer) (when (not (eq nil deft-note-mode)) (setq count (1+ count)) (kill-buffer buffer)))))) (defun ragone-deft-or-close () "Kill all Deft buffers." (interactive) (if (or (eq major-mode 'deft-mode) (not (eq nil deft-note-mode))) (progn (ragone-kill-deft-buffers) (kill-buffer "*Deft*")) (deft)))