Add functions to insert images using SXIV

This commit is contained in:
Thomas Dehaeze 2020-04-06 00:11:22 +02:00
parent 328c03392f
commit 151290829d

View File

@ -1698,6 +1698,45 @@ Insert Image that is in the figs folder
(insert (format "[[file:%s]]" img))) (insert (format "[[file:%s]]" img)))
#+end_src #+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: Take Screenshot and insert a link:
- Ask for a name =screenshot_name= - Ask for a name =screenshot_name=
- use =maim -s figs/screenshot_name.png= to take a screenshot with selection - 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 "p" 'tdh-insert-paper-org-link
:n "n" 'tdh-insert-note-org-link :n "n" 'tdh-insert-note-org-link
:n "f" 'tdh-insert-image-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))) :n "s" 'tdh-insert-screenshot-org-link)))
#+end_src #+end_src
@ -2127,6 +2168,28 @@ This function:
:n "<C-S-return>" #'tdh-ctrl-shift-ret) :n "<C-S-return>" #'tdh-ctrl-shift-ret)
#+end_src #+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= ** Helping Functions - Tangling =,b=
Org-Babel Tangle Sub-tree Org-Babel Tangle Sub-tree
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -2142,19 +2205,19 @@ Org-Babel Tangle Sub-tree
Org-Tangle and Org-Babel Jump to Tangle File Org-Tangle and Org-Babel Jump to Tangle File
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun tdh-org-babel-jump-to-tangle-file () (defun tdh-org-babel-jump-to-tangle-file ()
"Jump to tangle file for the source block at point." "Jump to tangle file for the source block at point."
(interactive) (interactive)
(let (file org-babel-pre-tangle-hook org-babel-post-tangle-hook) (let (file org-babel-pre-tangle-hook org-babel-post-tangle-hook)
(cl-letf (((symbol-function 'write-region) (lambda (start end filename &rest _ignore) (cl-letf (((symbol-function 'write-region) (lambda (start end filename &rest _ignore)
(setq file filename))) (setq file filename)))
((symbol-function 'delete-file) #'ignore)) ((symbol-function 'delete-file) #'ignore))
(org-babel-tangle '(4))) (org-babel-tangle '(4)))
(when file (when file
(setq file (expand-file-name file)) (setq file (expand-file-name file))
(if (file-readable-p file) (if (file-readable-p file)
(find-file file) (find-file file)
(error "Cannot open tangle file %S" file))))) (error "Cannot open tangle file %S" file)))))
#+end_src #+end_src
Map Functions Map Functions