diff options
author | Yuchen Pei <id@ypei.org> | 2024-12-31 10:04:11 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2024-12-31 10:04:11 +1100 |
commit | 82cf9a13134204b87b7fe01d1cebdf5771d7cebb (patch) | |
tree | 2bda461dbfcdb9656e9d43bc36090f5a82b0901c /emacs/.emacs.d | |
parent | 0584de27f0fc5039e0198732385e0fdcbe41d924 (diff) |
[emacs] various changes
* emacs/.emacs.d/init/ycp-basic.el: forgot to read
my-copy-file-targets from local config
* emacs/.emacs.d/init/ycp-markup.el: Key in nov mode to copy file to devices
* emacs/.emacs.d/init/ycp-org.el: Back to use browse-url for http /
https org links
* emacs/.emacs.d/init/ycp-pdf.el: forgot to read my-pdf-dptrp1-ip from
local config
* emacs/.emacs.d/init/ycp-web.el: add a handler for mariadb kb links
* emacs/.emacs.d/lisp/my/my-emms.el: mp4 can be audio
* emacs/.emacs.d/lisp/my/my-mariadb.el: a predicate for browse-url to
determine mariadb kb links
* emacs/.emacs.d/lisp/my/my-nov.el: add a command to copy current epub
to a device
* emacs/.emacs.d/lisp/my/my-org.el: ensure leading and trailing
empty lines are deleted in org-edit-special; factor out copy file to
device with staging to my-utils, fix my-org-edit-special-after
argument numbers for one more time (it is 0 with src and 1 with example)
* emacs/.emacs.d/lisp/my/my-utils.el: mp4 could be audio; a function
to copy files to device with staging, factored from my-org
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/init/ycp-basic.el | 1 | ||||
-rw-r--r-- | emacs/.emacs.d/init/ycp-markup.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/init/ycp-org.el | 12 | ||||
-rw-r--r-- | emacs/.emacs.d/init/ycp-pdf.el | 1 | ||||
-rw-r--r-- | emacs/.emacs.d/init/ycp-web.el | 2 | ||||
m--------- | emacs/.emacs.d/lisp/exitter | 0 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-emms.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-mariadb.el | 3 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-nov.el | 12 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-org.el | 54 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-utils.el | 71 | ||||
m--------- | emacs/.emacs.d/lisp/nov.el | 0 |
12 files changed, 112 insertions, 48 deletions
diff --git a/emacs/.emacs.d/init/ycp-basic.el b/emacs/.emacs.d/init/ycp-basic.el index 12c21d1..6baf1b8 100644 --- a/emacs/.emacs.d/init/ycp-basic.el +++ b/emacs/.emacs.d/init/ycp-basic.el @@ -57,6 +57,7 @@ (:delay 5) (my-setq-from-local my-audio-incoming-dir my-video-incoming-dir my-document-incoming-dir) + (my-setq-from-local my-copy-file-targets) (my-keybind global-map "C-c <f2>" #'my-rename-file-and-buffer "C-c <delete>" #'my-delete-file-and-kill-buffer diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el index e03fd86..d55586d 100644 --- a/emacs/.emacs.d/init/ycp-markup.el +++ b/emacs/.emacs.d/init/ycp-markup.el @@ -94,6 +94,8 @@ (require 'my-nov) (my-override nov-render-title) (my-override nov-scroll-up) + (my-keybind nov-mode-map + "Q" #'my-nov-copy-buffer-file-with-staging) ) ;;; json-mode diff --git a/emacs/.emacs.d/init/ycp-org.el b/emacs/.emacs.d/init/ycp-org.el index eb5a63d..bb1b828 100644 --- a/emacs/.emacs.d/init/ycp-org.el +++ b/emacs/.emacs.d/init/ycp-org.el @@ -504,12 +504,12 @@ (my-package my-org (:delay 30) (require 'my-web) - (org-link-set-parameters "http" :follow (lambda (url arg) - (my-browse-url - (concat "http:" url) arg))) - (org-link-set-parameters "https" :follow (lambda (url arg) - (my-browse-url - (concat "https:" url) arg))) + (org-link-set-parameters "http" :follow + (lambda (url arg) + (browse-url (concat "http:" url) arg))) + (org-link-set-parameters "https" :follow + (lambda (url arg) + (browse-url (concat "http:" url) arg))) (require 'eww) (define-key eww-mode-map (kbd "C-'") 'my-eww-org-protocol-grok) ) diff --git a/emacs/.emacs.d/init/ycp-pdf.el b/emacs/.emacs.d/init/ycp-pdf.el index 9553f7a..8e47f1c 100644 --- a/emacs/.emacs.d/init/ycp-pdf.el +++ b/emacs/.emacs.d/init/ycp-pdf.el @@ -57,6 +57,7 @@ "," #'my-pdf-view-shrink-a-bit "Q" #'my-pdf-dptrp1-upload ) + (my-setq-from-local my-pdf-dptrp1-ip) ) (my-package pdf-misc diff --git a/emacs/.emacs.d/init/ycp-web.el b/emacs/.emacs.d/init/ycp-web.el index c50cc46..ffdb83d 100644 --- a/emacs/.emacs.d/init/ycp-web.el +++ b/emacs/.emacs.d/init/ycp-web.el @@ -254,6 +254,8 @@ . ,(lambda (url &rest _) (exitter-open-post url))) (my-hacker-news-url-p . ,(lambda (url &rest _) (hnreader-comment url))) + (my-mariadb-kb-url-p + . ,(lambda (url &rest _) (my-mariadb-fetch-kb-source url))) (my-mastodon-url-p . ,(lambda (url &rest _) (mastorg-open url))) (my-newscorp-au-url-p diff --git a/emacs/.emacs.d/lisp/exitter b/emacs/.emacs.d/lisp/exitter -Subproject c78c62bd4a0eca87ae711d1efbd3f0cca46faf7 +Subproject e0aa1eb8b5dd2696f92f90348cb9e8aedd79800 diff --git a/emacs/.emacs.d/lisp/my/my-emms.el b/emacs/.emacs.d/lisp/my/my-emms.el index ffb6bc0..803ac0a 100644 --- a/emacs/.emacs.d/lisp/my/my-emms.el +++ b/emacs/.emacs.d/lisp/my/my-emms.el @@ -165,7 +165,7 @@ either 'audio or 'video (if (and (length> players 1) (string-prefix-p "file://" name) (member (file-name-extension name) - '("mkv" "mp4" "ogv" "avi" "webm"))) + '("mkv" "ogv" "avi" "webm"))) 'emms-player-vlc 'emms-player-mpv))) diff --git a/emacs/.emacs.d/lisp/my/my-mariadb.el b/emacs/.emacs.d/lisp/my/my-mariadb.el index 6b0e06b..01bc063 100644 --- a/emacs/.emacs.d/lisp/my/my-mariadb.el +++ b/emacs/.emacs.d/lisp/my/my-mariadb.el @@ -251,6 +251,9 @@ enum spider_malloc_id { nil t) (tempel-insert 'ps))) +(defun my-mariadb-kb-url-p (url) + (string-match-p "https://mariadb.com/kb/en/\\([^/]+\\)/" url)) + (defun my-mariadb-fetch-kb-source (url) "Fetches the source to an maridb kb entry at URL. diff --git a/emacs/.emacs.d/lisp/my/my-nov.el b/emacs/.emacs.d/lisp/my/my-nov.el index 863d09a..4e2f60a 100644 --- a/emacs/.emacs.d/lisp/my/my-nov.el +++ b/emacs/.emacs.d/lisp/my/my-nov.el @@ -52,5 +52,17 @@ chapter title." (nov-next-document) (follow-scroll-up arg))) +(defun my-nov-copy-buffer-file-with-staging () + (interactive) + (unless (derived-mode-p 'nov-mode) (error "Not in nov mode")) + (pcase-let* ((name + (completing-read (format "Copy %s to: " nov-file-name) + my-copy-file-targets + nil t)) + (`(,dest ,staging) (alist-get name my-copy-file-targets + nil nil #'equal))) + (my-copy-file-with-staging + nov-file-name dest staging))) + (provide 'my-nov) ;;; my-nov.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el index ad0c3cb..e99352d 100644 --- a/emacs/.emacs.d/lisp/my/my-org.el +++ b/emacs/.emacs.d/lisp/my/my-org.el @@ -81,7 +81,12 @@ buffer was a live window.") (defun my-org-edit-src-before-exit () "A :before advice for org-edit-src-exit." - (delete-trailing-whitespace) + (goto-char (point-min)) + (and + (>= (skip-chars-forward "\n") 1) + (region-modifiable-p (point-min) (point)) + (delete-region (point-min) (point))) + (let ((delete-trailing-lines t)) (delete-trailing-whitespace)) (setq my-org-edit-src-was-live-window (get-buffer-window (current-buffer)))) (defun my-org-element-block-p (element) @@ -812,8 +817,6 @@ When BLOCK-REGEXP is non-nil, use this regexp to find blocks." (cl-letf (((symbol-function 'delete-other-windows) 'ignore)) (apply oldfun args))) -(defvar my-org-attach-copy-attached-targets nil - "Alist of targets to copy attached to, in the form of (name . path)") (defvar my-org-attach-copy-attached-doc-exts '("epub" "pdf" "mobi")) (defvar my-org-attach-copy-attached-doc-re @@ -832,44 +835,15 @@ On success, also move everything from staging to to-dir." (interactive) (pcase-let* ((name (completing-read "Copy attached docs to: " - my-org-attach-copy-attached-targets + my-copy-file-targets nil t)) - (`(,to ,staging) (alist-get name my-org-attach-copy-attached-targets + (`(,to ,staging) (alist-get name my-copy-file-targets nil nil #'equal))) - (let ((basedir (org-attach-dir)) - (failed nil)) - (dolist (attached (org-attach-file-list basedir)) - (when (string-match my-org-attach-copy-attached-doc-re attached) - (message "Copying %s to %s (%s)..." attached name to) - (condition-case nil - (copy-file (file-name-concat basedir attached) - (file-name-concat - to - (replace-regexp-in-string ":" "_" attached)) - t) - (error - (message "Hardlinking %s to %s staging area (%s)" - attached name staging) - (setq failed t) - (add-name-to-file - (file-name-concat basedir attached) - (file-name-concat - staging - (replace-regexp-in-string ":" "_" attached)) - t))) - (message "Done!"))) - (unless failed - (dolist (staged - (directory-files staging nil - my-org-attach-copy-attached-doc-re)) - (message "Moving staged %s to %s (%s)..." staged name to) - (copy-file (file-name-concat staging staged) - (file-name-concat - to - (replace-regexp-in-string ":" "_" staged)) - t) - (delete-file (file-name-concat staging staged)) - (message "Done!")))))) + (my-copy-files-with-staging + (directory-files-recursively (org-attach-dir) + my-org-attach-copy-attached-doc-re) + to + staging))) (defun my-org-attach-all-url-plaintext (arg) (interactive "P") @@ -1365,7 +1339,7 @@ With a prefix arg, yank and exit immediately." (org-edit-src-exit)))) ;; used to add an :after advice to `org-edit-special'. -(defun my-org-edit-special-after () +(defun my-org-edit-special-after (&rest _) ;; some modes (e.g. diff mode) are read-only by default, which ;; does not make sense when the intention is to edit (read-only-mode 0)) diff --git a/emacs/.emacs.d/lisp/my/my-utils.el b/emacs/.emacs.d/lisp/my/my-utils.el index bc200c2..3ecd0a9 100644 --- a/emacs/.emacs.d/lisp/my/my-utils.el +++ b/emacs/.emacs.d/lisp/my/my-utils.el @@ -321,7 +321,7 @@ Example: (format-time-string ... (my-time-from-epoch 1698582504))" (defvar my-extension-types '((audio . ("asf" "cue" "flac" "m4a" "m4r" "mid" "mp3" "ogg" "opus" - "wav" "wma" "spc")) + "wav" "wma" "spc" "mp4")) (video . ("avi" "m4v" "mkv" "mp4" "mpg" "ogg" "ogv" "rmvb" "webm" "wmv")))) ;;; files @@ -332,6 +332,75 @@ Example: (format-time-string ... (my-time-from-epoch 1698582504))" (make-symbolic-link newname file ok-if-already-exists) newname) +(defvar my-copy-file-targets nil + "Alist of targets to copy attached to, in the form of (name dest staging)") + +(defun my-copy-buffer-file-with-staging () + (interactive) + (unless (buffer-file-name) (error "buffer-file-name is nil")) + (pcase-let* ((name + (completing-read (format "Copy %s to: " (buffer-file-name)) + my-copy-file-targets + nil t)) + (`(,dest ,staging) (alist-get name my-copy-file-targets + nil nil #'equal))) + (my-copy-file-with-staging + (buffer-file-name) dest staging))) + +(defun my-flush-staging-files (staging dest) + "Flush files from STAGING to DEST." + (dolist (staged (directory-files staging)) + (unless (file-directory-p (file-name-concat staging staged)) + (message "Moving staged %s to %s..." staged dest) + (copy-file (file-name-concat staging staged) + (file-name-concat dest staged) + t) + (delete-file (file-name-concat staging staged))))) + +(defun my-flush-staging-files-x () + (interactive) + (pcase-let* ((name + (completing-read (format "Copy %s to: " (buffer-file-name)) + my-copy-file-targets + nil t)) + (`(,dest ,staging) (alist-get name my-copy-file-targets + nil nil #'equal))) + (my-flush-staging-files staging dest))) + +(defun my-copy-file-with-staging (src dest staging) + "Copy a file SRC to DEST with fallback to hardlinking to STAGING." + (my-copy-files-with-staging (list src) dest staging)) + +(defun my-copy-files-with-staging (src dest staging) + "Copy a list of file SRC to DEST with staging. + +DEST and STAGING should be directories. +On failure, hard link to STAGING. +On success, also move everything from STAGING to DEST." + (cl-assert (listp src)) + (let (failed) + (dolist (file src) + (cond + ((not failed) + (message "Copying %s to %s..." file dest) + (condition-case err + (copy-file + file (file-name-concat dest (file-name-nondirectory file)) t) + (error + (message "Encountered error while copying: %s" + (error-message-string err)) + (message "Hardlinking instead %s to staging area %s" src staging) + (setq failed t) + (add-name-to-file + file (file-name-concat staging (file-name-nondirectory file)) t)))) + (t + (message "Hardlinking %s staging area %s" src staging) + (add-name-to-file + file (file-name-concat staging (file-name-nondirectory file)) t)))) + (unless failed + (my-flush-staging-files staging dest)) + (message "Done!"))) + (defun my-rewrite-url-advice (args) (let ((url (car args))) (setcar args (my-rewrite-url url))) diff --git a/emacs/.emacs.d/lisp/nov.el b/emacs/.emacs.d/lisp/nov.el -Subproject b3c7cc28e95fe25ce7b443e5f49e2e45360944a +Subproject bbb5c60bfd6b09cffe0406a56930105335f0788 |