emacs: fix nil file-name-handler-alist after reloading init
[~bandali/configs] / .emacs.d / init.el
index c2b20ba..b09f080 100644 (file)
       esup-child-profile-require-level 0)
 
 ;; set them back to their defaults once we're done initializing
-(add-hook
- 'after-init-hook
- (lambda ()
-   (setq gc-cons-threshold a/gc-cons-threshold
-         gc-cons-percentage a/gc-cons-percentage
-         file-name-handler-alist a/file-name-handler-alist)))
+(defun a/post-init ()
+  (setq gc-cons-threshold a/gc-cons-threshold
+        gc-cons-percentage a/gc-cons-percentage
+        file-name-handler-alist a/file-name-handler-alist))
+(add-hook 'after-init-hook #'a/post-init)
 
 ;; increase number of lines kept in *Messages* log
 (setq message-log-max 20000)
@@ -93,7 +92,9 @@
 ;; Not necessary when using straight.el
 ;;   (C-h v straight-package-neutering-mode RET)
 
-(comment
+(when (and
+       (not (featurep 'straight))
+       (version< emacs-version "27"))
   (setq package-enable-at-startup nil)
   ;; (package-initialize)
   )
   (interactive)
   (straight-transaction
     (straight-mark-transaction-as-init)
-    (load user-init-file)))
+    (setq a/file-name-handler-alist file-name-handler-alist)
+    (load user-init-file)
+    (a/post-init)))
 
 ;; use-package
 (straight-use-package 'use-package)
   (exec-path-from-shell-copy-env "SSH_AGENT_PID")
   (exec-path-from-shell-copy-env "SSH_AUTH_SOCK"))
 
-
 ;; only one custom theme at a time
 (comment
   (defadvice load-theme (before clear-previous-themes activate)
@@ -443,6 +445,14 @@ For disabling the behaviour for certain buffers and/or modes."
 ;; allow scrolling in Isearch
 (setq isearch-allow-scroll t)
 
+(use-feature vc
+  :bind ("C-x v C-=" . vc-ediff))
+
+(use-feature ediff
+  :config (add-hook 'ediff-after-quit-hook-internal 'winner-undo)
+  :custom ((ediff-window-setup-function 'ediff-setup-windows-plain)
+           (ediff-split-window-function 'split-window-horizontally)))
+
 \f
 ;;; General bindings
 
@@ -457,7 +467,7 @@ For disabling the behaviour for certain buffers and/or modes."
 
  ("C-c F m" . make-frame-command)
  ("C-c F d" . delete-frame)
- ("C-c F D" . delete-other-frames)
+ ("C-c F D" . server-edit)
 
  ("C-c o"   . other-window)
 
@@ -538,6 +548,7 @@ For disabling the behaviour for certain buffers and/or modes."
   (("C-c a o a" . org-agenda)
    :map org-mode-map
    ("M-L" . org-insert-last-stored-link)
+   ("M-O" . org-toggle-link-display)
    ("s-T" . org-todo))
   :hook ((org-mode . org-indent-mode)
          (org-mode . auto-fill-mode)
@@ -626,6 +637,7 @@ For disabling the behaviour for certain buffers and/or modes."
   (nconc magit-section-initial-visibility-alist
          '(([unpulled status] . show)
            ([unpushed status] . show)))
+  :custom (magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
   :custom-face (magit-diff-file-heading ((t (:weight normal)))))
 
 ;; recently opened files
@@ -852,6 +864,17 @@ For disabling the behaviour for certain buffers and/or modes."
                         (setq ediff-after-quit-hook-internal nil)
                         (set-window-configuration wnd))))
         (error "no more than 2 files should be marked"))))
+
+  (require 'dired-x)
+  (setq dired-guess-shell-alist-user
+        '(("\\.pdf\\'"  "evince" "zathura" "okular")
+          ("\\.doc\\'"  "libreoffice")
+          ("\\.docx\\'" "libreoffice")
+          ("\\.ppt\\'"  "libreoffice")
+          ("\\.pptx\\'" "libreoffice")
+          ("\\.xls\\'"  "libreoffice")
+          ("\\.xlsx\\'" "libreoffice")
+          ("\\.flac\\'" "mpv")))
   :bind (:map dired-mode-map
               ("b"  . dired-up-directory)
               ("e"  . dired-ediff-files)
@@ -886,6 +909,7 @@ For disabling the behaviour for certain buffers and/or modes."
 
 ;; highlight uncommitted changes in the left fringe
 (use-package diff-hl
+  :defer 0.6
   :config
   (setq diff-hl-draw-borders nil)
   (global-diff-hl-mode)
@@ -1369,13 +1393,17 @@ For disabling the behaviour for certain buffers and/or modes."
 
 (use-package multi-term
   :defer 0.6
-  :bind (("C-c a s m" . multi-term-dedicated-toggle)
+  :bind (("C-c a s m m" . multi-term)
+         ("C-c a s m d" . multi-term-dedicated-toggle)
+         ("C-c a s m p" . multi-term-prev)
+         ("C-c a s m n" . multi-term-next)
          :map term-mode-map
-         ("C-c C-j" . term-char-mode)
-         :map term-raw-map
-         ("C-c C-j" . term-line-mode))
+         ("C-c C-j" . term-char-mode))
   :config
-  (setq multi-term-program "/bin/screen"
+  (setq multi-term-program "screen"
+        multi-term-program-switches (concat "-c"
+                                            (getenv "XDG_CONFIG_HOME")
+                                            "/screen/screenrc")
         ;; TODO: add separate bindings for connecting to existing
         ;; session vs. always creating a new one
         multi-term-dedicated-select-after-open-p t
@@ -1384,19 +1412,36 @@ For disabling the behaviour for certain buffers and/or modes."
         term-bind-key-alist
         '(("C-c C-c" . term-interrupt-subjob)
           ("C-c C-e" . term-send-esc)
+          ("C-c C-j" . term-line-mode)
           ("C-k" . kill-line)
-          ("C-y" . term-paste)
+          ;; ("C-y" . term-paste)
+          ("C-y" . term-send-raw)
           ("M-f" . term-send-forward-word)
           ("M-b" . term-send-backward-word)
           ("M-p" . term-send-up)
           ("M-n" . term-send-down)
+          ("M-j" . term-send-raw-meta)
+          ("M-y" . term-send-raw-meta)
+          ("M-/" . term-send-raw-meta)
+          ("M-0" . term-send-raw-meta)
+          ("M-1" . term-send-raw-meta)
+          ("M-2" . term-send-raw-meta)
+          ("M-3" . term-send-raw-meta)
+          ("M-4" . term-send-raw-meta)
+          ("M-5" . term-send-raw-meta)
+          ("M-6" . term-send-raw-meta)
+          ("M-7" . term-send-raw-meta)
+          ("M-8" . term-send-raw-meta)
+          ("M-9" . term-send-raw-meta)
           ("<C-backspace>" . term-send-backward-kill-word)
           ("<M-DEL>" . term-send-backward-kill-word)
           ("M-d" . term-send-delete-word)
           ("M-," . term-send-raw)
           ("M-." . comint-dynamic-complete))
         term-unbind-key-alist
-        '("C-z" "C-x" "C-c" "C-h" "C-y" "<ESC>")))
+        '("C-z" "C-x" "C-c" "C-h"
+          ;; "C-y"
+          "<ESC>")))
 
 (use-package page-break-lines
   :defer 0.5
@@ -1496,6 +1541,10 @@ For disabling the behaviour for certain buffers and/or modes."
   :init
   (setq alert-default-style 'notifier))
 
+(use-package ivy-xref
+  :init
+  (setq xref-show-xrefs-function #'ivy-xref-show-xrefs))
+
 \f
 ;;; Email (with Gnus)
 
@@ -1607,7 +1656,9 @@ For disabling the behaviour for certain buffers and/or modes."
      ("gnu.*"
       (gcc-self . t))
      ("gnu\\."
-      (subscribed . t)))
+      (subscribed . t))
+     ("nnimap\\+uw:.*"
+      (gcc-self . t)))
    gnus-large-newsgroup  50
    gnus-home-directory   (no-littering-expand-var-file-name "gnus/")
    gnus-directory        (concat gnus-home-directory "news/")
@@ -1679,12 +1730,13 @@ For disabling the behaviour for certain buffers and/or modes."
            (to "webmasters-comment@gnu.org")
            (body "Added  to 2019supporters.html.\n\nMoving to campaigns.\n\n-amin\n")
            (eval (setq a/message-cite-say-hi nil)))
-          ("nnimap\\+uwaterloo:.*"
-           (address "abandali@uwaterloo.ca")
-           (gcc "\"nnimap+uwaterloo:Sent Items\""))
-          ("nnimap\\+csclub:.*"
+          ("nnimap\\+uw:.*"
+           (address "abandali@uwaterloo.ca"))
+          ("nnimap\\+uw:INBOX"
+           (gcc "\"nnimap+uw:Sent Items\""))
+          ("nnimap\\+csc:.*"
            (address "abandali@csclub.uwaterloo.ca")
-           (gcc "nnimap+csclub:Sent")))))
+           (gcc "nnimap+csc:Sent")))))
 
 (use-feature gnus-topic
   :hook (gnus-group-mode . gnus-topic-mode)
@@ -1699,6 +1751,17 @@ For disabling the behaviour for certain buffers and/or modes."
   :config
   (setq gnus-permanently-visible-groups "\\(:INBOX$\\|:gnu$\\)"))
 
+(comment
+  ;; problematic with ebdb's popup, *EBDB-Gnus*
+  (use-feature gnus-win
+    :config
+    (setq gnus-use-full-window nil)))
+
+(use-feature gnus-dired
+  :commands gnus-dired-mode
+  :init
+  (add-hook 'dired-mode-hook 'gnus-dired-mode))
+
 (use-feature mm-decode
   :config
   (setq mm-discouraged-alternatives '("text/html" "text/richtext")))