Add some new functions

* Run function on a region of text
* Mark text as translatable by Jinja
* URL encode/decode text
This commit is contained in:
Gergely Polonkai 2018-09-06 14:04:55 +02:00
parent 9c8b47b54b
commit 2ba993bf2e

View File

@ -121,6 +121,17 @@ Taken from [[http://ergoemacs.org/emacs/emacs_set_backup_into_a_directory.html][
(make-directory (file-name-directory backup-file-path) (file-name-directory backup-file-path))
backup-file-path))
#+END_SRC
*** Run a function on a region
#+BEGIN_SRC emacs-lisp
(defun func-region (start end func)
"Run a function over the region between START and END in current buffer."
(save-excursion
(let ((text (delete-and-extract-region start end)))
(insert (funcall func text)))))
#+END_SRC
** Check if we are running under Termux
We need to do things differently, if so.
@ -758,6 +769,39 @@ Copied from https://ryuslash.org/posts/C-d-to-close-eshell.html
`(gpolonkai/idm-get-field-for-account ,account 'account-id))
#+END_SRC
** Jinja related
*** Mark a string as translatable
#+BEGIN_SRC emacs-lisp
(defun jinja-mark-translatable (begin end)
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list (point-min) (point-max))))
(save-excursion
(goto-char end)
(insert "{% endtrans %}")
(goto-char begin)
(insert "{% trans %}")))
#+END_SRC
*** URL-ify and de-URL-ify region
These functions URL-encode/decode a text. Might be helpful when embedding/extracting data to/from
HTML.
#+BEGIN_SRC emacs-lisp
(defun hex-region (start end)
"urlencode the region between START and END in current buffer."
(interactive "r")
(func-region start end #'url-hexify-string))
(defun unhex-region (start end)
"de-urlencode the region between START and END in current buffer."
(interactive "r")
(func-region start end #'url-unhex-string))
#+END_SRC
** Automatically zone out after 60 seconds
#+BEGIN_SRC emacs-lisp