From c96ad072199e46a3e4eaf864149018764fb66212 Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Mon, 6 Apr 2020 00:11:22 +0200 Subject: [PATCH] Add functions to insert images using SXIV --- dotfiles/doom.org | 89 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 13 deletions(-) diff --git a/dotfiles/doom.org b/dotfiles/doom.org index 3155f08..fbbcb08 100644 --- a/dotfiles/doom.org +++ b/dotfiles/doom.org @@ -1698,6 +1698,45 @@ Insert Image that is in the figs folder (insert (format "[[file:%s]]" img))) #+end_src +Insert Image that is in the =figs= folder using SXIV +#+begin_src emacs-lisp + (defun tdh-insert-image-org-link-sxiv () + "Insert an org image link, choosing the file with completion + and starting from `my-default-image-directory'." + (interactive) + (setq img (shell-command-to-string "ls figs/*.{jpg,jpeg,bmp,png,gif} 2> /dev/null | sxiv -i -t -o | tail -1 | tr -d '\n'")) + (unless (equal "" img) + (insert (format "[[file:%s]]" img))) + ) +#+end_src + +Copy picture from phone folder using SXIV and insert it +#+begin_src emacs-lisp + (defun tdh-insert-phone-picture () + (interactive) + (setq img (shell-command-to-string "~/.config/doom/bin/copy-phone-picture.sh")) + (unless (equal "" img) + (insert (format "[[file:%s]]" img))) + ) +#+end_src + +Bash script for copying pictures taken by phone. +#+begin_src bash :comments both :mkdirp yes :shebang "#!/usr/bin/env bash" :tangle ~/.config/doom/bin/copy-phone-picture.sh + if [ -z "$1" ]; then + oldpath=$(ls -t ~/Cloud/photos/phone/*.jpg | sxiv -i -t -o | tail -1); + else + oldpath=$(ls -t $1 | sxiv -i -t -o | tail -1); + fi + + if [ -n "$oldpath" ]; then + newfilename=$(basename $oldpath .jpg | rofi -i -dmenu -p "Filename") + if [ -n "$newfilename" ]; then + cp $oldpath "figs/$newfilename.jpg" + printf "figs/$newfilename.jpg" + fi + fi +#+end_src + Take Screenshot and insert a link: - Ask for a name =screenshot_name= - use =maim -s figs/screenshot_name.png= to take a screenshot with selection @@ -1722,6 +1761,8 @@ Map Keys :n "p" 'tdh-insert-paper-org-link :n "n" 'tdh-insert-note-org-link :n "f" 'tdh-insert-image-org-link + :n "F" 'tdh-insert-image-org-link-sxiv + :n "i" 'tdh-insert-phone-picture :n "s" 'tdh-insert-screenshot-org-link))) #+end_src @@ -2127,6 +2168,28 @@ This function: :n "" #'tdh-ctrl-shift-ret) #+end_src +** Align Source Blocks +#+begin_src emacs-lisp + (defun tdh-align-src-block () + (interactive) + (defun in-src-block-p () + "Returns t when the point is inside a source code block" + (string= "src" (org-in-block-p '("src")))) + + (if (in-src-block-p) + (progn + (org-edit-special) + (evil-indent (point-min) (point-max)) + (org-edit-src-exit)) + (org-table-eval-formula))) +#+end_src + +#+begin_src emacs-lisp + (map! :after evil-org + :map evil-org-mode-map + :n "C-c =" #'tdh-align-src-block) +#+end_src + ** Helping Functions - Tangling =,b= Org-Babel Tangle Sub-tree #+begin_src emacs-lisp @@ -2142,19 +2205,19 @@ Org-Babel Tangle Sub-tree Org-Tangle and Org-Babel Jump to Tangle File #+begin_src emacs-lisp -(defun tdh-org-babel-jump-to-tangle-file () - "Jump to tangle file for the source block at point." - (interactive) - (let (file org-babel-pre-tangle-hook org-babel-post-tangle-hook) - (cl-letf (((symbol-function 'write-region) (lambda (start end filename &rest _ignore) - (setq file filename))) - ((symbol-function 'delete-file) #'ignore)) - (org-babel-tangle '(4))) - (when file - (setq file (expand-file-name file)) - (if (file-readable-p file) - (find-file file) - (error "Cannot open tangle file %S" file))))) + (defun tdh-org-babel-jump-to-tangle-file () + "Jump to tangle file for the source block at point." + (interactive) + (let (file org-babel-pre-tangle-hook org-babel-post-tangle-hook) + (cl-letf (((symbol-function 'write-region) (lambda (start end filename &rest _ignore) + (setq file filename))) + ((symbol-function 'delete-file) #'ignore)) + (org-babel-tangle '(4))) + (when file + (setq file (expand-file-name file)) + (if (file-readable-p file) + (find-file file) + (error "Cannot open tangle file %S" file))))) #+end_src Map Functions