summaryrefslogtreecommitdiff
path: root/emacs/init.el
blob: a5a19684f4abc7f6dcb729266b9154878ed5537b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;;; init.el --- Emacs configuration -*- lexical-binding: t; -*-

;;; Appearance

(menu-bar-mode -1)
(setq inhibit-startup-screen t
      ring-bell-function 'ignore)
(setq-default display-line-numbers-type t)
(global-display-line-numbers-mode 1)
(column-number-mode 1)
(blink-cursor-mode -1)

;;; Editing

(global-set-key (kbd "C-l") #'goto-line)
(setq-default indent-tabs-mode nil)
(setq make-backup-files nil
      auto-save-default nil)
(global-set-key (kbd "C-x w") #'kill-region)
(electric-pair-mode 1)
(add-hook 'text-mode-hook #'visual-line-mode)

;;; Eshell

(setq eshell-prompt-function (lambda () "> ")
      eshell-prompt-regexp "^> ")

(use-package eat
  :ensure t
  :hook (eshell-load . eat-eshell-mode)
  :custom (eshell-visual-commands nil))

;;; Navigation and completion

(fido-vertical-mode 1)

(global-set-key (kbd "C-c p f") #'project-find-file)

;;; Languages

;; Install grammars with M-x treesit-install-language-grammar.
(require 'treesit)

(setq major-mode-remap-alist
      '((go-mode . go-ts-mode)
        (rust-mode . rust-ts-mode)))

(setq treesit-language-source-alist
      '((go . ("https://github.com/tree-sitter/tree-sitter-go"
               "v0.23.4"))
        (rust . ("https://github.com/tree-sitter/tree-sitter-rust"
                 "v0.23.3"))))

(add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode))
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode))

(setq auto-mode-alist
      (append '(("\\.pl\\'" . cperl-mode)
                ("\\.pm\\'" . cperl-mode))
              auto-mode-alist))

(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))

(use-package markdown-mode
  :ensure t
  :mode ("\\.md\\'" . gfm-mode)
  :hook (markdown-mode . visual-line-mode))

;;; Git

(global-set-key (kbd "C-x g") #'magit-status)
;; Git verifies SSH signatures using gpg.ssh.allowedSignersFile.
;; Show signature status on commit hashes by default.
(with-eval-after-load 'magit-log
  (let ((defaults (get 'magit-log-mode 'magit-log-default-arguments)))
    (put 'magit-log-mode 'magit-log-default-arguments
         (cl-adjoin "--show-signature" defaults :test #'equal))))

;;; SSH agent

(defun my/refresh-keychain-env ()
  "Query the keychain tool directly to import SSH agent configurations."
  (interactive)
  (when (executable-find "keychain")
    (let ((env (shell-command-to-string "keychain -q --noask --eval")))
      (when (string-match "SSH_AUTH_SOCK[=\\s]\\\"?\\([^\\s;\\n\\\"]*\\)" env)
        (setenv "SSH_AUTH_SOCK" (match-string 1 env)))
      (when (string-match "SSH_AGENT_PID[=\\s]\\\"?\\([0-9]*\\)" env)
        (setenv "SSH_AGENT_PID" (match-string 1 env))))))

(my/refresh-keychain-env)

;;; Package selections managed by Customize

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(magit)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;;; init.el ends here