From 837317997e05c02df56c30d2be6726e03dfa0812 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 18 Jun 2022 00:41:10 +0300 Subject: [PATCH] Move the Vertalen section to after package initialization --- .emacs.d/esy.org | 166 +++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/.emacs.d/esy.org b/.emacs.d/esy.org index f4b51a2..01fc28d 100644 --- a/.emacs.d/esy.org +++ b/.emacs.d/esy.org @@ -127,89 +127,6 @@ For further information about Elisp headers, see [[info:elisp#Library (load-theme 'modus-vivendi) #+end_src -* Dutch to English translation with =define-word= and [[https://www.vertalen.nu/][vertalen.nu]] -:PROPERTIES: -:CUSTOM_ID: vertalen -:END: - -#+begin_src emacs-lisp - (defun vertalen--on-success (&rest args) - "Process ARGS and display translation in a dedicated buffer." - (with-current-buffer-window "*vertalen*" - (with-selected-window (selected-window) - (unless (eq major-mode 'vertalen-mode) - `(nil . ((inhibit-same-window . t))))) - #'fit-window-to-buffer - (setq tabulated-list-entries (plist-get args :data)) - (vertalen-mode) - (+ 2 (length tabulated-list-entries)))) - - (defun vertalen--parse () - (require 'dom) - "Parse buffer and return a list of translations." - (let* ((dom (libxml-parse-html-region (point-min) (point-max))) - (res (dom-by-class dom ".*result-item-translations.*")) - (ret nil)) - (dolist (elem res) - (setq ret - `((nil ,(vector - (apply #'concat - (dom-strings - (car (dom-by-class - elem - ".*result-item-source.*")))) - (mapconcat #'identity - (dom-strings - (car (dom-by-class - elem - ".*result-item-target.*"))) - ", "))) - . ,ret))) - (reverse ret))) - - (setq vertalen--source nil) - (setq vertalen-history nil) - - (with-eval-after-load 'savehist - (add-to-list 'savehist-additional-variables - 'vertalen-history)) - - (defun vertalen (word) - "Translate WORD." - (interactive (list (read-string "Translate: " nil 'vertalen-history (thing-at-point 'word)))) - (require 'request) - (setq vertalen--source word) - (request "https://www.vertalen.nu/vertaal" - :params `(("van" . "nl") - ("naar" . "en") - ("vertaal" . ,word)) - :parser #'vertalen--parse - :success #'vertalen--on-success)) - - (defun vertalen-at-point () - "Translate word at point." - (interactive nil vertalen-mode) - (vertalen (thing-at-point 'word t))) - - (defvar-keymap vertalen-mode-map - :doc "Keymap for `vertalen-mode' buffers." - "RET" #'vertalen-at-point) - - (define-derived-mode vertalen-mode tabulated-list-mode "Vertalen" - "Major mode for listing Dutch to English translations." - (setq tabulated-list-format [("Source Language" 64 t) - ("Target Language" 32 t)]) - (tabulated-list-init-header) - (tabulated-list-print) - (save-excursion - (goto-char (point-min)) - (let ((inhibit-read-only t) - (word (search-forward vertalen--source nil t))) - (while word - (add-face-text-property (match-beginning 0) (match-end 0) 'success) - (setq word (search-forward vertalen--source nil t)))))) -#+end_src - * Package archives :PROPERTIES: :CUSTOM_ID: package-archives @@ -1047,6 +964,89 @@ does in the shell. (slack-start)) #+end_src +* Dutch to English translation with =define-word= and [[https://www.vertalen.nu/][vertalen.nu]] +:PROPERTIES: +:CUSTOM_ID: vertalen +:END: + +#+begin_src emacs-lisp + (defun vertalen--on-success (&rest args) + "Process ARGS and display translation in a dedicated buffer." + (with-current-buffer-window "*vertalen*" + (with-selected-window (selected-window) + (unless (eq major-mode 'vertalen-mode) + `(nil . ((inhibit-same-window . t))))) + #'fit-window-to-buffer + (setq tabulated-list-entries (plist-get args :data)) + (vertalen-mode) + (+ 2 (length tabulated-list-entries)))) + + (defun vertalen--parse () + (require 'dom) + "Parse buffer and return a list of translations." + (let* ((dom (libxml-parse-html-region (point-min) (point-max))) + (res (dom-by-class dom ".*result-item-translations.*")) + (ret nil)) + (dolist (elem res) + (setq ret + `((nil ,(vector + (apply #'concat + (dom-strings + (car (dom-by-class + elem + ".*result-item-source.*")))) + (mapconcat #'identity + (dom-strings + (car (dom-by-class + elem + ".*result-item-target.*"))) + ", "))) + . ,ret))) + (reverse ret))) + + (setq vertalen--source nil) + (setq vertalen-history nil) + + (with-eval-after-load 'savehist + (add-to-list 'savehist-additional-variables + 'vertalen-history)) + + (defun vertalen (word) + "Translate WORD." + (interactive (list (read-string "Translate: " nil 'vertalen-history (thing-at-point 'word)))) + (require 'request) + (setq vertalen--source word) + (request "https://www.vertalen.nu/vertaal" + :params `(("van" . "nl") + ("naar" . "en") + ("vertaal" . ,word)) + :parser #'vertalen--parse + :success #'vertalen--on-success)) + + (defun vertalen-at-point () + "Translate word at point." + (interactive nil vertalen-mode) + (vertalen (thing-at-point 'word t))) + + (defvar-keymap vertalen-mode-map + :doc "Keymap for `vertalen-mode' buffers." + "RET" #'vertalen-at-point) + + (define-derived-mode vertalen-mode tabulated-list-mode "Vertalen" + "Major mode for listing Dutch to English translations." + (setq tabulated-list-format [("Source Language" 64 t) + ("Target Language" 32 t)]) + (tabulated-list-init-header) + (tabulated-list-print) + (save-excursion + (goto-char (point-min)) + (let ((inhibit-read-only t) + (word (search-forward vertalen--source nil t))) + (while word + (add-face-text-property (match-beginning 0) (match-end 0) 'success) + (setq word (search-forward vertalen--source nil t)))))) +#+end_src + * Display weekly agenda on startup :PROPERTIES: :CUSTOM_ID: agenda-on-startup -- 2.39.5