summaryrefslogtreecommitdiff
path: root/.emacs.d/init.el
blob: 2f3f4a4cf8e5f746e4504ca941af52a2feaad762 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
(setq org-dir "~/syncthing/notes/Org")
;; Disable native compilation
(setq org-export-with-drawers t)

(setq make-backup-files nil)

(setq default-directory (file-name-as-directory org-dir))
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(defun generate-new-file-name () "Ask for a title and generate a file name based on it"
  (let* ((file-name (read-string "Title: "))
         (my-path (concat
                    org-dir ; Or whatever path you want
                    (format-time-string "%Y%m%d%H%M%S") "-"
                    (replace-regexp-in-string "[^a-zA-Z0-9-]+" "-" file-name) ".org"))) ; Replace invalid path characters
    (setq mc/org-capture-filename file-name) ; Save variable to be used later in the template
    my-path))


(setq inhibit-startup-message t)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(set-fringe-mode 10)


(menu-bar-mode -1)
(setq visible-bell t)

(if (daemonp)
    (add-hook 'after-make-frame-functions
              (lambda (frame)
                (with-selected-frame frame
                  (set-face-attribute 'default nil :font "Hack NF" :height 220))))
  (set-face-attribute 'default nil :font "Hack NF" :height 220))



;; Make ESC quit prompts
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)

;; Initialize package sources
(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("org" . "https://orgmode.org/elpa/")
                         ("elpa" . "https://elpa.gnu.org/packages/")))

(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

;; Initialize use-package on non-Linux platforms
(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure t)

;;; Enable all 3 for relative number mode
;; (column-number-mode)
;; (global-display-line-numbers-mode t)
;; (setq display-line-numbers-type 'relative)

;; Disable line numbers for some modes
(dolist (mode '(term-mode-hook
                 eshell-mode-hook))
  (add-hook mode (lambda () (display-line-numbers-mode 0))))

;; (use-package command-log-mode)
(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.
 '(org-agenda-files nil)
 '(package-selected-packages
   '(counsel doom-modeline doom-themes evil evil-collection evil-escape
	     evil-org general helpful htmlize ivy ivy-rich
	     org-contacts org-download org-roam projectile
	     rainbow-delimiters which-key)))
(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.
 )

(use-package ivy
             :diminish
             :bind (("C-s" . swiper)
                    :map ivy-minibuffer-map
                    ("TAB" . ivy-alt-done)	
                    ("C-l" . ivy-alt-done)
                    ("C-j" . ivy-next-line)
                    ("C-k" . ivy-previous-line)
                    :map ivy-switch-buffer-map
                    ("C-k" . ivy-previous-line)
                    ("C-l" . ivy-done)
                    ("C-d" . ivy-switch-buffer-kill)
                    :map ivy-reverse-i-search-map
                    ("C-k" . ivy-previous-line)
                    ("C-d" . ivy-reverse-i-search-kill))
             :demand
             :config
             (ivy-mode 1))


(use-package doom-modeline
             :ensure t
             :init (doom-modeline-mode 1)
             :custom ((doom-modeline-height 15)))
(use-package rainbow-delimiters
             :hook (prog-mode . rainbow-delimiters-mode))

(use-package doom-themes)
:init (load-theme 'doom-dracula t)

(use-package which-key
             :init (which-key-mode)
             :diminish which-key-mode
             :config
             (setq which-key-idle-delay 1))

(use-package ivy-rich
             :init
             (ivy-rich-mode 1))

(use-package counsel
             :bind (("M-x" . counsel-M-x)
                    ("C-x b" . counsel-ibuffer)
                    ("C-x C-f" . counsel-find-file)
                    :map minibuffer-local-map
                    ("C-r" . 'counsel-minibuffer-history))
             :config
             (setq ivy-initial-inputs-alist nil)) ;;Don't start searches with ^

(use-package helpful
             :ensure t
             :custom
             (counsel-describe-function-function #'helpful-callable)
             (counsel-describe-variable-function #'helpful-variable)
             :bind
             ([remap describe-function] . counsel-describe-function)
             ([remap describe-command] . helpful-command)
             ([remap describe-variable] . counsel-describe-variable)
             ([remap describe-key] . helpful-key))
(global-set-key (kbd "C-q") 'save-buffers-kill-terminal)
(use-package general)
(general-create-definer my-leader-def
                        ;; :prefix my-leader
                        :prefix "SPC")
(my-leader-def
  :states  'normal
  :keymaps 'override
  ;; bind "SPC a"
  "oa" 'org-agenda
  "oc" 'org-capture
  ;; "ot" 'org-todo
  ;; "ox" 'org-toggle-checkbox
  "og" 'counsel-org-tag
  "osg" 'org-tags-view
  ;; "op" 'org-set-property
  "oid" 'org-id-get-create
  "os" 'org-display-inline-images
  "oh" 'org-remove-inline-images
  "e" 'ido-find-file
  "w" 'save-buffer
  "b" 'ido-switch-buffer
  "gg" 'counsel-rg
  "q" 'quit-window
  "Q" 'kill-buffer-and-window
  "z" 'org-toggle-link-display
  "ff" 'projectile-find-file-in-known-projects)
;; "q" 'kill-this-buffer)
;; Enable Evil
(use-package evil
             :init
             (setq evil-want-integration t)
             (setq evil-want-keybinding nil)
             (setq evil-want-C-u-scroll t)
             (setq evil-want-C-i-jump nil)
             :config
             (define-key evil-insert-state-map (kbd "C-g") 'evil-normal-state)
             (define-key evil-insert-state-map (kbd "C-h") 'evil-delete-backward-char-and-join)
             (define-key evil-motion-state-map (kbd "C-h h") 'evil-window-left)
             (define-key evil-motion-state-map (kbd "C-a l") 'evil-window-right)
             (define-key evil-motion-state-map (kbd "C-a j") 'evil-window-down)
             (define-key evil-motion-state-map (kbd "C-a k") 'evil-window-up)
             (evil-mode 1))
;; Add this to your Evil configuration section, after (evil-mode 1)

;; Configure cursor shapes for different Evil states
(setq evil-normal-state-cursor '(box "orange"))
(setq evil-insert-state-cursor '(bar "red"))
(setq evil-visual-state-cursor '(hollow "purple"))
(setq evil-replace-state-cursor '(hbar "green"))
(setq evil-operator-state-cursor '(hbar "yellow"))

;; For terminal emacs, ensure cursor type changes are sent to terminal
(unless (display-graphic-p)
  ;; Define cursor change function
  (defun my/change-cursor-shape (shape)
    (send-string-to-terminal (format "\033[%d q" shape)))
  
  ;; Enable cursor shape changes in terminal
  (add-hook 'evil-insert-state-entry-hook (lambda () (my/change-cursor-shape 6))) ; Bar
  (add-hook 'evil-normal-state-entry-hook (lambda () (my/change-cursor-shape 2))) ; Block
  (add-hook 'evil-visual-state-entry-hook (lambda () (my/change-cursor-shape 2))) ; Block
  (add-hook 'evil-replace-state-entry-hook (lambda () (my/change-cursor-shape 4))) ; Underline
  (add-hook 'evil-operator-state-entry-hook (lambda () (my/change-cursor-shape 4))) ; Underline
  
  ;; Reset cursor on exit
  (add-hook 'kill-emacs-hook (lambda () (my/change-cursor-shape 2))))
(use-package evil-collection
             :after evil
             :config
             (evil-collection-init))

(use-package evil-escape
             :config
             (evil-escape-mode 1))
(setq-default evil-escape-key-sequence "jk")

(defun mm/org-mode-setup()
  (org-indent-mode)
  (variable-pitch-mode 1)
  (auto-fill-mode 0)
  (visual-line-mode 1)
  (global-visual-line-mode 1)
  (setq evil-auto-indent nil)
  )
(evil-define-key 'normal 'global (kbd "g j") 'evil-next-visual-line)
(evil-define-key 'normal 'global (kbd "g k") 'evil-previous-visual-line)
(evil-define-key 'normal org-mode-map (kbd "g j") 'evil-next-visual-line)
(evil-define-key 'normal org-mode-map (kbd "g k") 'evil-previous-visual-line)

(use-package org
  :hook (org-mode . mm/org-mode-setup)
  :config
  ;; Load org configuration from separate file
  (add-to-list 'load-path org-dir) ;; Adjust path as needed
  (require 'org-config))
(use-package org-download)

(setq org-file-apps '((t . "gio open %s"))) ;;For Windows, to open files with an external program
(add-hook 'dired-mode-hook 'org-download-enable)

;; (setq org-startup-with-inline-images t)
(use-package htmlize)
(use-package org-roam
             :ensure t
             :custom
             (org-roam-directory (org-dir))
             :bind (("C-c n l" . org-roam-buffer-toggle)
                    ("C-c n f" . org-roam-node-find)
                    ("C-c n g" . org-roam-graph)
                    ("C-c n i" . org-roam-node-insert)
                    ("C-c n c" . org-roam-capture)
                    ;; Dailies
                    ("C-c n j" . org-roam-dailies-capture-today))
             :config
             ;; If you're using a vertical completion framework, you might want a more informative completion interface
             (setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
             (org-roam-db-autosync-mode)
             ;; If using org-roam-protocol
             (require 'org-roam-protocol))
(require 'org-id)
(setq org-id-link-to-org-use-id t)
;; (setq org-roam-dailies-capture-templates
;;       '(("d" "default" entry
;;          "* Section 1\n** Section 1.1\n* Section 2\n"
;;          :target (file+head "%<%Y-%m-%d>.org"
;;                             "#+title: %<%Y-%m-%d>\n"))
;; ("n" "default" entry
;;          "* Section 1\n** Section 1.1\n* Section 2\n"
;;          :target (file+head "%<%Y-%m-%d>.org"
;;                             "#+title: %<%Y-%m-%d>\n"))
;;         ))

(setq org-agenda-start-on-weekday 1)
(setq calendar-date-style 'iso)
(setq calendar-week-start-day 1)
(setq org-read-date-force-compatible-dates nil)

(use-package projectile)
(projectile-mode +1)
(setq projectile-known-projects (list org-dir))
;; Recommended keymap prefix on Windows/Linux
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)

(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c C-l") 'org-insert-link)

;; Disable the annoying mini buffer when inserting a link
(add-to-list
 'display-buffer-alist
 `("*Org Links*" display-buffer-no-window (allow-no-window . t)))


;; (setq org-time-stamp-formats '("%Y-%m-%d %a %H:%M"))
(setq org-clock-persist 'history)
(org-clock-persistence-insinuate)
(defun my/timenow ()
 (interactive)
 (let ((current-prefix-arg '(16)))
   (call-interactively 'org-time-stamp-inactive)))

(define-key org-mode-map (kbd "C-c m") 'my/timenow)

;; Add a direct shortcut for file links with autocomplete
  (defun my/org-insert-file-link ()
    "Insert a file link directly, with path autocomplete and description prompt."
    (interactive)
    (let* ((org-link-file-path-type 'relative)
           (file-path (org-link-complete-file))
           ;; Remove file: prefix if it's already there
           (path (substring file-path 5))
           (desc (read-string "Description: " nil nil nil t)))
      (org-insert-link nil (concat "file:" path) (if (string= desc "") nil desc))))

  ;; Bind it to C-c C-f
  (define-key org-mode-map (kbd "C-c C-f") 'my/org-insert-file-link)
Back to https://optics-design.com