Commit 1b152a3df6c2

Vincent Demeester <vincent@sbr.pm>
2025-02-24 19:04:54
tools/emacs: various cleanup and formatting
1 parent 1abe8d6
tools/emacs/config/config-completion.el
@@ -160,43 +160,43 @@ The symbol at point is added to the future history."
   (define-key embark-buffer-map (kbd "s l") (ct/embark-display-in-side-window left))
   (define-key embark-buffer-map (kbd "s r") (ct/embark-display-in-side-window right))
   
-(defun embark-which-key-indicator ()
-  "An embark indicator that displays keymaps using which-key.
+  (defun embark-which-key-indicator ()
+    "An embark indicator that displays keymaps using which-key.
 The which-key help message will show the type and value of the
 current target followed by an ellipsis if there are further
 targets."
-  (lambda (&optional keymap targets prefix)
-    (if (null keymap)
-        (which-key--hide-popup-ignore-command)
-      (which-key--show-keymap
-       (if (eq (plist-get (car targets) :type) 'embark-become)
-           "Become"
-         (format "Act on %s '%s'%s"
-                 (plist-get (car targets) :type)
-                 (embark--truncate-target (plist-get (car targets) :target))
-                 (if (cdr targets) "…" "")))
-       (if prefix
-           (pcase (lookup-key keymap prefix 'accept-default)
-             ((and (pred keymapp) km) km)
-             (_ (key-binding prefix 'accept-default)))
-         keymap)
-       nil nil t (lambda (binding)
-                   (not (string-suffix-p "-argument" (cdr binding))))))))
+    (lambda (&optional keymap targets prefix)
+      (if (null keymap)
+          (which-key--hide-popup-ignore-command)
+	(which-key--show-keymap
+	 (if (eq (plist-get (car targets) :type) 'embark-become)
+             "Become"
+           (format "Act on %s '%s'%s"
+                   (plist-get (car targets) :type)
+                   (embark--truncate-target (plist-get (car targets) :target))
+                   (if (cdr targets) "…" "")))
+	 (if prefix
+             (pcase (lookup-key keymap prefix 'accept-default)
+               ((and (pred keymapp) km) km)
+               (_ (key-binding prefix 'accept-default)))
+           keymap)
+	 nil nil t (lambda (binding)
+                     (not (string-suffix-p "-argument" (cdr binding))))))))
 
-(setq embark-indicators
-  '(embark-which-key-indicator
-    embark-highlight-indicator
-    embark-isearch-highlight-indicator))
+  (setq embark-indicators
+	'(embark-which-key-indicator
+	  embark-highlight-indicator
+	  embark-isearch-highlight-indicator))
 
-(defun embark-hide-which-key-indicator (fn &rest args)
-  "Hide the which-key indicator immediately when using the completing-read prompter."
-  (which-key--hide-popup-ignore-command)
-  (let ((embark-indicators
-         (remq #'embark-which-key-indicator embark-indicators)))
+  (defun embark-hide-which-key-indicator (fn &rest args)
+    "Hide the which-key indicator immediately when using the completing-read prompter."
+    (which-key--hide-popup-ignore-command)
+    (let ((embark-indicators
+           (remq #'embark-which-key-indicator embark-indicators)))
       (apply fn args)))
 
-(advice-add #'embark-completing-read-prompter
-            :around #'embark-hide-which-key-indicator))
+  (advice-add #'embark-completing-read-prompter
+              :around #'embark-hide-which-key-indicator))
 
 (use-package embark-consult
   :after (embark consult)
@@ -244,7 +244,7 @@ targets."
   (setq corfu-popupinfo-delay '(1.25 . 0.5))
   (corfu-popupinfo-mode 1)
   (corfu-candidate-overlay-mode)
-    ;; Sort by input history (no need to modify `corfu-sort-function').
+  ;; Sort by input history (no need to modify `corfu-sort-function').
   (with-eval-after-load 'savehist
     (corfu-history-mode 1)
     (add-to-list 'savehist-additional-variables 'corfu-history))
@@ -281,7 +281,7 @@ Useful for prompts such as `eval-expression' and `shell-command'."
 	'(orderless basic substring initials flex partial-completion))
   (setq completion-category-defaults nil)
   (setq completion-category-overrides nil)
-)
+  )
 
 (use-package tempel
   :bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
tools/emacs/config/config-vcs.el
@@ -151,6 +151,7 @@
     (th/magit--with-difftastic
      (get-buffer-create name)
      `("git" "--no-pager" "diff" "--ext-diff" ,@(when arg (list arg))))))
+
 (use-package magit
   :unless noninteractive
   :commands (magit-status magit-clone magit-pull magit-blame magit-log-buffer-file magit-log)
@@ -197,8 +198,8 @@
 ;;   (message foo)
 ;;   (git-commit--insert-trailer "Hello" foo))
 
-  (magit-define-popup-option 'magit-rebase-popup
-                             ?S "Sign using gpg" "--gpg-sign=" #'magit-read-gpg-secret-key)
+  ;; (magit-define-popup-option 'magit-rebase-popup
+  ;;                            ?S "Sign using gpg" "--gpg-sign=" #'magit-read-gpg-secret-key)
   (magit-define-popup-switch 'magit-log-popup
                              ?m "Omit merge commits" "--no-merges")
   ;; cargo-culted from https://github.com/magit/magit/issues/3717#issuecomment-734798341
@@ -291,6 +292,5 @@
   :bind
   ("C-x v /" . consult-vc-modified-files))
 
-
 (provide 'config-vcs)
 ;;; config-vcs.el ends here
tools/emacs/config/config-web.el
@@ -74,19 +74,19 @@
   :after eww
   :config
 
-  (defun browse-url-xdg-desktop-portal (url &rest args)
-    "Open URL via a portal backend."
-    (dbus-call-method :session
-                      "org.freedesktop.portal.Desktop"
-                      "/org/freedesktop/portal/desktop"
-                      "org.freedesktop.portal.OpenURI"
-                      "OpenURI"
-                      "" url '(:array :signature "{sv}")))
-  (setopt browse-url-browser-function #'browse-url-xdg-desktop-portal)
+  ;; (defun browse-url-xdg-desktop-portal (url &rest args)
+  ;;   "Open URL via a portal backend."
+  ;;   (dbus-call-method :session
+  ;;                     "org.freedesktop.portal.Desktop"
+  ;;                     "/org/freedesktop/portal/desktop"
+  ;;                     "org.freedesktop.portal.OpenURI"
+  ;;                     "OpenURI"
+  ;;                     "" url '(:array :signature "{sv}")))
+  ;; (setopt browse-url-browser-function #'browse-url-xdg-desktop-portal)
   ;; (setq browse-url-browser-function #'eww-browse-url)
 
   ;; (setq browse-url-generic-program "google-chrome-stable")
-  (setq browse-url-handlers '(("^https://gitlab.com.*" . browse-url-firefox)
+  (setq browse-url-handlers '(("^https://gitlab.com.*" . browse-url-default-browser)
                               ("^https://github.com.*" . browse-url-default-browser)
                               ("^https://issues.redhat.com.*" . browse-url-default-browser)
                               ("^https://.*redhat.com.*" . browse-url-default-browser)
tools/emacs/config/programming-config.el
@@ -162,6 +162,12 @@
                              (if test-name `["-test.run" ,test-name]
                                (error "No test selected")))))))))
 
+(defconst markdown-regex-italic
+    "\\(?:^\\|[^\\]\\)\\(?1:\\(?2:[_]\\)\\(?3:[^ \n\t\\]\\|[^ \n\t]\\(?:.\\|\n[^\n]\\)[^\\ ]\\)\\(?4:\\2\\)\\)")
+;; and/or
+(defconst markdown-regex-gfm-italic
+    "\\(?:^\\|[^\\]\\)\\(?1:\\(?2:[_]\\)\\(?3:[^ \\]\\2\\|[^ ]\\(?:.\\|\n[^\n]\\)\\)\\(?4:\\2\\)\\)")
+
 (use-package markdown-mode
   :commands (markdown-mode gfm-mode)
   :mode (("README\\.md\\'" . gfm-mode)
@@ -178,7 +184,7 @@
 (use-package copilot
   :hook
   (prog-mode . copilot-mode)
-  (markdown-mode . copilot-mode)
+  ;; (markdown-mode . copilot-mode) ;; Enable this on-demand only
   ;; (text-mode . copilot-mode) ;; I may not want copilot in org-mode for example.
   (log-edit-mode . copilot-mode)
   (vc-git-log-edit-mode . copilot-mode)