From 2ba993bf2ef29f5925b3c56c1e1a37514ad2dadf Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 6 Sep 2018 14:04:55 +0200 Subject: [PATCH] Add some new functions * Run function on a region of text * Mark text as translatable by Jinja * URL encode/decode text --- configuration.org | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/configuration.org b/configuration.org index 16f17d8..d44ec5b 100644 --- a/configuration.org +++ b/configuration.org @@ -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