-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-mini.el
2968 lines (2527 loc) · 99.6 KB
/
init-mini.el
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; init-mini.el --- SeJ Emacs configurations. -*- lexical-binding: t no-byte-compile: t; -*-
;; Copyright (C) 2019 Stephen Jenkins
;; Author: Stephen Jenkins
;; URL: https://github.com/sejgit/.emacs.d
;; Version: 0.0.1
;; Keywords: .emacs.d sejgit
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;; Commentary:
;;
;; SeJ Emacs mini configurations.
;;
;; for use on smaller systems or installations
;; just do a ln -s ~/.emacs.d/init-mini.el ~/.emacs
;;; Changelog
;;
;; <2023-01-02 Mon> take init.el and start chopping
;;; Code:
(message "Emacs start")
;;; initialize environment
;;;;; debug
;; only turned on when needed
;; (setq debug-on-error t)
;; (setq debug-on-event t)
;;;;; Straight package manager set-up
(setq-default straight-repository-branch "develop"
straight-fix-org t
straight-fix-flycheck t
straight-use-package-by-default t
straight-check-for-modifications '(check-on-save find-when-checking))
(setq vc-follow-symlinks t)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;;;;; Use-Package set-up
;; - https://github.com/jwiegley/use-package
;; - https://github.com/emacsmirror/diminish
;; - https://github.com/jwiegley/use-package/blob/master/bind-key.el
;; - https://github.com/jwiegley/use-package#use-package-ensure-system-package
;; Should set before loading `use-package'
(setq-default use-package-always-defer t
use-package-compute-statistics t
use-package-expand-minimally t
use-package-enable-imenu-support t)
(straight-use-package 'use-package)
;;;;; bind-key
;; Required by `use-package'
(use-package bind-key
:bind ("s-d" . describe-personal-keybindings))
;;;;; Blackout
;; Similar to packages like minions, diminish, or delight.
;; You can alter how your minor and major modes show up in the mode-line.
;; [[https://github.com/raxod502/blackout][Blackout]]
(use-package blackout
:demand t
:straight (:host github :repo "raxod502/blackout"))
;; Auto installing OS system packages
;; ensure-system-package keyword to ensure system binaries exist alongside your package
(use-package use-package-ensure-system-package
:ensure t)
;;;;; system custom constants
;; - section for global constants
(defconst sys/win32p
(eq system-type 'windows-nt)
"Are we running on a WinTel system?")
(defconst sys/linuxp
(eq system-type 'gnu/linux)
"Are we running on a GNU/Linux system?")
(defconst sys/macp
(eq system-type 'darwin)
"Are we running on a Mac system?")
(defconst sys/mac-x-p
(and (display-graphic-p) sys/macp)
"Are we running under X on a Mac system?")
(defconst sys/linux-x-p
(and (display-graphic-p) sys/linuxp)
"Are we running under X on a GNU/Linux system?")
(defconst sys/cygwinp
(eq system-type 'cygwin)
"Are we running on a Cygwin system?")
(defconst sys/rootp
(string-equal "root" (getenv "USER"))
"Are you using ROOT user?")
(defconst emacs/>=26p
( >= emacs-major-version 26 )
"Emacs is 26 or above.")
(defconst emacs/>27p
(> emacs-major-version 27)
"Emacs is 28 or above.")
;;;;; should i even be here
(when (not emacs/>27p)
(error "This requires Emacs 28 and above") )
;;;;; Warnings
;; set-up server & suppress warnings
;; - [[https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/warnings.el][warnings.el]]
(require 'warnings)
;; remove warnings for cl depreciated and server already running
(setq warning-suppress-types (quote ((cl server iedit))))
(setq warning-suppress-log-types (quote ((cl) )))
(setq byte-compile-warnings '(cl-functions))
;;;;; Server set-up
;; set-up Emacs server
(use-package emacs
:when (or sys/macp sys/linuxp)
:straight (:type built-in)
:hook (emacs-startup . sej/server-mode)
:config
(defun sej/server-mode ()
"Start server-mode without errors"
(interactive)
(with-demoted-errors
"%S -- Server exists -- not starting new one."
(load "server")
(unless (server-running-p) (server-start)) ) ) )
;;;;; GCMH
;; The Garbage Collector Magic Hack
;; [[https://github.com/emacsmirror/gcmh][github gcmh]]
(use-package gcmh
:blackout t
:straight t
:hook (after-init . gcmh-mode)
:init
(add-hook 'focus-out-hook #'gcmh-idle-garbage-collect)
(add-hook 'suspend-hook #'gcmh-idle-garbage-collect)
(setq gcmh-idle-delay 10))
;;;;; restart-emacs
;; simple package to restart Emacs within Emacs
;; with a single universal-argument (C-u) Emacs is restarted with --debug-init flag
;; with two universal-argument (C-u C-u) Emacs is restarted with -Q flag
;; with three universal-argument (C-u C-u C-u) the user is prompted for the arguments
;; restart-emacs-start-new-emacs starts new session of Emacs without killing the current one
;; [[https://github.com/iqbalansari/restart-emacs][restart-emacs]]
(use-package restart-emacs
:straight t
:init
(defalias 're #'restart-emacs))
;;;;; customization variables set
;; set-up Emacs customizations choices which are then modified by custom.el
(defgroup sej nil
"SeJ Emacs customizations."
:group 'convenience)
(defcustom sej-homepage "https://github.com/sejgit/.emacs.d"
"The Github page of Emacs Owner."
:type 'string)
(defcustom sej-full-name "Stephen Jenkins"
"Set user full name."
:type 'string)
(defcustom sej-mail-address "[email protected]"
"Set user email address."
:type 'string)
(defcustom sej-proxy "localhost:80"
"Set network proxy."
:type 'string)
(defcustom sej-dashboard t
"Use dashboard at startup or not. If Non-nil, use dashboard, otherwise will restore previous session."
:type 'boolean)
(defcustom sej-benchmark nil
"Enable the init benchmark or not."
:type 'boolean)
(defcustom sej-org-directory "~/Documents/orgtodo"
"Set org directory."
:type 'string)
(defcustom sej-project-org-capture-text "Project"
"Text for the Label for the Org Capture Project journal."
:type 'string)
(defcustom sej-project-org-capture-file "~/Documents/orgtodo/journal.org"
"Filename for the Org Capture Project Journal."
:type 'string)
(defcustom sej-latex-directory "/Library/TeX/texbin"
"Directory for Latex."
:type 'string)
(defcustom sej-irc-nick "nick"
"Nickname for ERC/IRC."
:type 'string)
(defcustom sej-irc-pass "pass"
"Password for ERC/IRC."
:type 'string)
;;;;; Load `custom-file'
;; If it doesn't exist, copy from the template, then load it.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(let ((custom-template-file
(expand-file-name "custom-template.el" user-emacs-directory)))
(if (and (file-exists-p custom-template-file)
(not (file-exists-p custom-file)))
(copy-file custom-template-file custom-file)))
(if (file-exists-p custom-file)
(load custom-file :noerror))
;;;;; Load `custom-post.el'
;; Put personal configurations to override defaults here.
;; place to hold specific & secret stuff ~/.ssh is best
(progn
(let ((file
(expand-file-name "custom-post.el" user-emacs-directory)))
(if (file-exists-p file)
(load file :noerror)))
(let ((file
(expand-file-name "custom-post.el" "~/.ssh/")))
(if (file-exists-p file)
(load file :noerror))) )
;;;;; exec-path-from-shell
;; set-up exec-path and hook for server-start
;; [[https://github.com/purcell/exec-path-from-shell][exec-path-from-shell]]
(use-package exec-path-from-shell
:demand t
:straight t
:when (or sys/macp sys/linuxp daemonp)
:init
(setq exec-path-from-shell-variables '("DOTFILES"
"EDITOR"
"EMACS"
"PYENV_ROOT"
"IPYTHONDIR"
"PYTHONSTARTUP"
"PYLINTHOME"
"FZF_DEFAULT_COMMAND"
"HIST_IGNORE"
"HISTSIZE"
"SAVEHIST"
"SSH_AUTH_SOCK"
"TREE_SITTER_DIR"
"JAVA_HOME"
"ZSH"
"PATH"
"MANPATH"
"FPATH"
)
exec-path-from-shell-arguments '("-l"))
:config
(exec-path-from-shell-initialize))
;;;;; Compdef
;; in buffer completion to set local completion backends
;; [[https://gitlab.com/jjzmajic/compdef][Compdef]]
(use-package compdef
:demand t
:straight (:host gitlab :repo "jjzmajic/compdef"))
;;;;; dash
;; A modern list API for Emacs. No 'cl required.
;; [[https://github.com/magnars/dash.el][dash.el]]
(use-package dash
:demand t
:straight t)
;;;;; f
;; modern API for working with files and directories in Emacs.
;; [[https://github.com/rejeep/f.el][f.el]]
(use-package f
:demand t
:straight t)
;;;;; s
;; The long lost Emacs string manipulation library.
;; [[https://github.com/magnars/s.el][s.el]]
(use-package s
:demand t
:straight t)
;;;;; cl-lib
;; These are extensions to Emacs Lisp that provide a degree of
;; Common Lisp compatibility, beyond what is already built-in
;; in Emacs Lisp.
;; [[https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/cl-lib.el][cl-lib.el]]
(use-package cl-lib
:demand t
:straight (:type built-in))
;;;;; Emacs internal settings
;; - a use-package friendly place to put settings
;; no real extra value to putting as setq but feels clean
(use-package emacs
:demand t
:straight (:type built-in)
:custom
;;;;;; general
(inhibit-startup-message t "No splash screen.")
(inhibit-startup-screen t)
(inhibit-startup-echo-area-message t)
(use-file-dialog nil)
(default-directory (f-expand "$HOME") "Set startup directory.")
(locate-command "which")
(message-log-max 16384 "Raise the maximum number of logs in the *Messages* buffer.")
(ad-redefinition-action 'accept "Remove irritating 'got redefined' messages.")
(hostname (replace-regexp-in-string "\\(^[[:space:]\n]*\\|[[:space:]\n]*$\\)" ""
(with-output-to-string (call-process "hostname"
nil
standard-output)))
"Figure out current hostname.")
(confirm-kill-processes nil "Allow exit without asking to kill processes.")
(visible-bell t "Flash for bell.")
(inhibit-compacting-font-caches t "Don’t compact font caches during GC.")
(use-dialog-box nil "Use echo areas for yes-no as well as file.")
(case-fold-search 1 "Ignore case when searching.")
(echo-keystrokes 0.1 "How quick to display multi-keystrokes.")
(next-line-add-newlines t "Add a new line when going to the next line.")
;;;;;; whitespace and end-of-buffer settings
(indicate-empty-lines t)
(indicate-buffer-boundaries t)
(show-trailing-whitespace nil)
(mode-require-final-newline nil)
(require-final-newline nil)
;;;;;; long line settings
(truncate-lines 1)
(font-lock-maximum-decoration t)
(truncate-partial-width-windows 1)
;;;;;; backups
(backup-directory-alist '(("." . ".saves")) "Don't litter my fs tree.")
(vc-make-backup-files t)
(backup-by-copying t)
(delete-old-versions t)
(kept-new-versions 6)
(kept-old-versions 2)
(version-control t)
;;;;;; mouse
(make-pointer-invisible t "Hide mouse while typing.")
;;;;;; kill & clipboard settings
(kill-buffer-query-functions
(remq 'process-kill-buffer-query-function
kill-buffer-query-functions)
"Remove kill buffer with live process prompt.")
(select-enable-clipboard t)
(x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;;;;;; adaptive fill settings
(adaptive-fill-regexp "[ t]+|[ t]*([0-9]+.|*+)[ t]*")
(adaptive-fill-first-line-regexp "^* *$")
;;;;;; UTF-8 please
(locale-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(set-keyboard-coding-system 'utf-8) ; pretty
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
:init
(setq sentence-end-double-space nil) ; Sentences do not need double spaces to end. Period.
(global-visual-line-mode t) ; Add proper word wrapping
(global-font-lock-mode t) ; turn on syntax highlighting for all buffers
;;;;;; color codes
(add-to-list 'comint-output-filter-functions 'ansi-color-process-output)
;;;;;; Deleting files go to OS's trash folder
(setq delete-by-moving-to-trash t)
(if sys/macp (setq trash-directory "~/.Trash"))
;;;;;; update time-stamps in files
(add-hook 'before-save-hook 'time-stamp)
;;;;;; yes and no settings
(defalias 'yes-or-no-p 'y-or-n-p)
;;;;;; Don't use GTK+ tooltip
(when (boundp 'x-gtk-use-system-tooltips)
(setq x-gtk-use-system-tooltips nil))
;;;;;; windows
(window-divider-mode) )
;;;;; Simple
;; built-in simple settings
;;
(use-package simple
:blackout ((visual-line-mode . "")
(auto-fill-mode . ""))
:straight (:type built-in)
:init
(setq blink-matching-paren 'jump-offscreen
column-number-mode t
delete-trailing-lines t
eval-expression-print-length nil
eval-expression-print-level nil
idle-update-delay 1
kill-do-not-save-duplicates t
kill-ring-max 300
track-eol t
line-move-visual nil
line-number-mode t
mode-line-percent-position nil
save-interprogram-paste-before-kill t
kill-read-only-ok t
shift-select-mode nil
show-trailing-whitespace nil
set-mark-command-repeat-pop t)
;; When popping the mark, continue popping until the cursor actually moves
;; Also, if the last command was a copy - skip past all the expand-region cruft.
(defadvice pop-to-mark-command (around ensure-new-position activate)
"When popping the mark, continue popping until we move the cursor."
(let ((p (point)))
(when (eq last-command 'save-region-or-current-line)
ad-do-it
ad-do-it
ad-do-it)
(dotimes (i 10)
(when (= p (point)) ad-do-it)))))
;;;;; minibuffer
;; minibuffer settings
;; [[https://github.com/emacs-mirror/emacs/blob/master/lisp/minibuffer.el][minibuffer.el]]
(use-package minibuffer
:no-require t
:straight (:type built-in)
:preface
;; Set garbage collection threshold
(defun sej/minibuffer-setup-hook ()
(setq gc-cons-threshold extended-gc-cons-threshold))
(defun sej/minibuffer-exit-hook ()
(setq gc-cons-threshold default-gc-cons-threshold))
(defun sej/always-exit-minibuffer-first ()
(if-let ((minibuffer (active-minibuffer-window)))
(with-current-buffer (window-buffer minibuffer)
(minibuffer-keyboard-quit))
(funcall keyboard-quit)))
:init
(add-hook 'minibuffer-setup-hook #'sej/minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'sej/minibuffer-exit-hook)
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
(advice-add #'sej/always-exit-minibuffer-first :around 'keyboard-quit)
:config
(setq completion-cycle-threshold 3
completion-flex-nospace nil
completion-pcm-complete-word-inserts-delimiters t
completion-pcm-word-delimiters "-_./:| "
completion-styles '(partial-completion substring initials flex)
completion-category-overrides '((file (styles initials basic))
(buffer (styles initials basic))
(info-menu (styles basic)))
completions-format 'vertical
read-answer-short t
read-buffer-completion-ignore-case t
read-file-name-completion-ignore-case t
resize-mini-windows t))
;;;;; uniquify
;; built-in package to make buffer names unique but identifiable
(use-package uniquify
:straight (:type built-in)
:init
(setq uniquify-ignore-buffers-re "^\\*"
uniquify-buffer-name-style 'post-forward-angle-brackets
uniquify-strip-common-suffix t
uniquify-after-kill-buffer-p t
uniquify-separator "/"))
;;;;; no-littering feature
;; set the default paths for configuration files & persistent data
;; [[https://github.com/emacscollective/no-littering][no-littering]]
(use-package no-littering
:demand t
:straight t
:init
(setq no-littering-etc-directory (expand-file-name "~/.local/share/emacs/")
no-littering-var-directory (expand-file-name "~/.cache/emacs/"))
(defalias 'nl-var-expand #'no-littering-expand-var-file-name)
(defalias 'nl-etc-expand #'no-littering-expand-etc-file-name)
(setq auto-save-file-name-transforms `((".*"
,(no-littering-expand-var-file-name "auto-save/") t))))
;;;;; OSX System specific environment setting
(when sys/macp
(setq exec-path (append exec-path '("/usr/local/bin")))
)
;;;;; Linux System specific environment setting
(when sys/linuxp
(setq exec-path (append exec-path '("/usr/local/bin")))
)
;;;;; Microsoft Windows specific environment settings
;; set execution paths
(when sys/win32p
(setenv "PATH"
(mapconcat
#'identity exec-path path-separator))
;; set exec-path for latex installation
(setq exec-path (append (list sej-latex-directory
"c:/msys64/mingw64/bin"
"/mingw64/bin/") exec-path)))
;;;;; sej-mode-map set-up
;; - Below taken from stackexchange (Emacs)
;; Main use is to have my key bindings have the highest priority
;; - https://github.com/kaushalmodi/.emacs.d/blob/master/elisp/modi-mode.el
(defvar sej-mode-map (make-sparse-keymap)
"Keymap for 'sej-mode'.")
;;;###autoload
(define-minor-mode sej-mode
"A minor mode so that my key settings override annoying major modes."
;; If init-value is not set to t, this mode does not get enabled in
;; `fundamental-mode' buffers even after doing \"(global-my-mode 1)\".
;; More info: http://emacs.stackexchange.com/q/16693/115
:init-value t
:lighter " sej"
:keymap sej-mode-map)
;;;###autoload
(define-globalized-minor-mode global-sej-mode sej-mode sej-mode)
;; https://github.com/jwiegley/use-package/blob/master/bind-key.el
;; The keymaps in `emulation-mode-map-alists' take precedence over
;; `minor-mode-map-alist'
(add-to-list 'emulation-mode-map-alists `((sej-mode . ,sej-mode-map)))
;; Turn off the minor mode in the minibuffer
(defun turn-off-sej-mode ()
"Turn off 'sej-mode'."
(sej-mode -1))
(add-hook 'minibuffer-setup-hook #'turn-off-sej-mode)
;;; general keybindings
;;;; modifiers
;;;;; OSX Apple keyboard
;; - caps lock is control (through karabiner)
;; Fn key do Hyper
;; LControl key do RControl (karabiner) which is Super (emacs)
;; left opt/alt key do emacs Alt modifier
;; right opt/alt key do regular alt key
;; left and right command(apple) key do Meta
;; spacebar acts as super key with other key
;; karabiner.json backup files in dotfiles under .config directory
;; - https://github.com/pqrs-org/Karabiner-Elements
(cond
(sys/macp ; OSX
(progn
(message "Mac OSX")
(if (boundp 'mac-carbon-version-string) ;; using mac-port?
( progn
;; for emacs-mac-port
(setq mac-right-command-modifier 'none) ;right command is left alone to mac
(setq mac-right-option-modifier 'none) ;Stays as alt key (like å∫ç∂)
(setq mac-function-modifier 'hyper) ;hyper is function & held tab key (Karabiner)
(setq mac-control-modifier 'control) ;Karabiner swapped & caps_lock
(setq mac-right-control-modifier 'super) ; actually left control
(setq mac-option-modifier 'alt) ; left option is A-alt key
(setq mac-command-modifier 'meta)) ;right command is meta
( progn
;; for regular Emacs port
(setq ns-right-command-modifier 'none)
(setq ns-right-option-modifier 'none)
(setq ns-function-modifier 'hyper)
(setq ns-control-modifier 'control)
(setq ns-right-control-modifier 'super)
(setq ns-option-modifier 'alt)
(setq ns-command-modifier 'meta)
)))))
;;;;; Windows keyboard
;; - CapsLock::LControl through AutoHotkeys
;; scroll lock do hyper (tab to scroll lock using AutoHotkeys)
;; Left control key do super (LControl::Appskey using AutoHotkeys)
;; Left Windows left alone due to win10 taking many keys
;; LAlt::Meta
;; RAlt::Alt modifier (RAlt::NumLock using Autohotkeys) **only works as tap & release
;; Rwin is Alt (not used in current laptop)
;; NOTE: only negative of this set-up is RAlt as numlock -> Alt is awkward push & release
;; - https://www.autohotkey.com/
(cond
(sys/win32p ; Microsoft Windows
(progn
(message "Microsoft Windows")
(setq w32-pass-lwindow-to-system t
w32-recognize-altgr nil
W32-enable-caps-lock nil
w32-pass-rwindow-to-system nil
w32-rwindow-modifier 'meta
w32-apps-modifier 'super
w32-pass-alt-to-system t
w32-alt-is-meta t
w32-scroll-lock-modifier 'hyper
w32-enable-num-lock nil)
(w32-register-hot-key [A-])
(define-key function-key-map (kbd "<kp-numlock>") 'event-apply-alt-modifier)
)))
;;;;; Linux keyboard
;; - nothing set at this moment
(cond
(sys/linuxp ; linux
(progn
(message "Linux")
;; load-dir init.d
)))
;;;; keybindings global
;;;;; shorthand for interactive lambdas
(defmacro λ (&rest body)
"Shorthand for interactive lambdas (BODY)."
`(lambda ()
(interactive)
,@body))
;;;;; transpose lines/words/sexps/params global
;; - Transpose stuff with M-t
(global-unset-key (kbd "M-t")) ;; which used to be transpose-words
(global-set-key (kbd "M-t l") 'transpose-lines)
(global-set-key (kbd "M-t w") 'transpose-words)
(global-set-key (kbd "M-t s") 'transpose-sexps)
(global-set-key (kbd "M-t p") 'transpose-params)
;;;;; special character definitions
;; - Neat bindings for C-x 8 ; put some Alt bindins there for fun as well
(global-set-key (kbd "C-x 8 l") (λ (insert "\u03bb")))
(global-set-key (kbd "A-L") (λ (insert "\u03bb")))
(global-set-key (kbd "C-x 8 t m") (λ (insert "™")))
(global-set-key (kbd "A-T") (λ (insert "™")))
(global-set-key (kbd "C-x 8 C") (λ (insert "©")))
(global-set-key (kbd "A-C") (λ (insert "©")))
(global-set-key (kbd "C-x 8 >") (λ (insert "→")))
(global-set-key (kbd "A->") (λ (insert "→")))
(global-set-key (kbd "C-x 8 8") (λ (insert "∞")))
(global-set-key (kbd "A-8") (λ (insert "∞")))
(global-set-key (kbd "C-x 8 v") (λ (insert "✓")))
(global-set-key (kbd "A-V") (λ (insert "✓")))
;;;;; sej-mode-map bindings
(unbind-key "C-z")
(unbind-key "M-z")
(global-unset-key (kbd "C-h C-h"))
;; unset C- and M- digit keys
(dotimes (n 10)
(global-unset-key (kbd (format "C-%d" n)))
(global-unset-key (kbd (format "M-%d" n))))
(bind-keys :prefix-map sej-mode-cz-map
:prefix "C-z"
:prefix-docstring "SeJ Personal cz-key bindings"
("v" . emacs-version)
("\\" . align-regexp) ;Align your code in a pretty way.
)
(bind-keys :map sej-mode-map
("C-c ." . org-time-stamp)
("s-." . pop-to-mark-command)
("C-h C-h" . nil)
("A-SPC" . cycle-spacing)
("M-j" . (lambda () (join-line -1)))
)
;;; general functions / packages
;;;;; sej/save-macro
;; - save last macro to init file
(defun sej/save-macro (name)
"Save a macro. Take a NAME as argument and save the last defined macro under this name at the end of your init file."
(interactive "SName of the macro :")
(kmacro-name-last-macro name)
(find-file user-init-file)
(goto-char (point-max))
(newline)
(insert-kbd-macro name)
(newline)
(switch-to-buffer nil))
;;;;; sej/exec
;; - executable functions from ohai and modified for my uses
;; - not key defined
(defun sej/exec (command)
"Run a shell COMMAND and return its output as a string, whitespace trimmed."
(interactive)
(s-trim (shell-command-to-string command)))
(defun sej/exec-with-rc (command &rest args)
"Run a shell COMMAND ARGS and return a list containing two values: its return code and its whitespace trimmed output."
(interactive)
(with-temp-buffer
(list (apply 'call-process command nil (current-buffer) nil args)
(s-trim (buffer-string)))))
(defun sej/is-exec (command)
"Return non-nil if COMMAND is an executable on the system search path."
(interactive)
(f-executable? (s-trim (shell-command-to-string (s-concat "which " command)))))
(defun sej/resolve-exec (command)
"If COMMAND is an executable on the system search path.
Return its absolute path. Otherwise, return nil."
(interactive)
(-let [path (s-trim (shell-command-to-string (s-concat "which " command)))]
(when (f-executable? path) path)))
(defun sej/exec-if-exec (command args)
"If COMMAND satisfies `sej/is-exec', run it with ARGS and return its output as per `sej/exec'. Otherwise, return nil."
(interactive)
(when (sej/is-exec command) (sej/exec (s-concat command " " args))))
;;;;; Advice
;; accept versus warn from the Advice system.
;; [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html][Advising Emacs Lisp Functions]]
(use-package advice
:straight (:type built-in)
:init
(setq-default ad-redefinition-action 'accept))
;;;; help
;;;;; help
;; help mode settings
;; [[https://github.com/emacs-mirror/emacs/blob/master/lisp/help-mode.el][help-mode.el]]
(use-package help
:straight (:type built-in)
:init
(add-hook 'help-mode-hook #'visual-line-mode)
(setq help-window-select 'always)
(advice-add 'help-window-display-message :override #'ignore))
;;;;; which-key
;; - minibuffer keybinding prompts
;; - https://github.com/justbur/emacs-which-key
(use-package which-key
:straight (which-key :type git :host github :repo "justbur/emacs-which-key")
:blackout t
:hook (emacs-startup . which-key-mode)
:commands which-key-mode
:defines sej-mode-map
:config
(setq which-key-use-C-h-commands t
which-key-separator " "
which-key-prefix-prefix "+")
(which-key-setup-side-window-bottom))
;;;;; helpful
;; - helpful is an improved help-fns & help-fns+
;; - https://github.com/Wilfred/helpful
(use-package helpful
:straight (helpful :type git :host github :repo "Wilfred/helpful")
:bind ( ("C-h C-d" . helpful-at-point)
("C-h c" . helpful-command)
("C-h C" . helpful-command)
("C-h k" . helpful-key) ; C-h k
("C-h v" . helpful-variable) ; C-h v
("C-h f" . helpful-callable) ; C-f v
("C-h M" . helpful-macro)) )
;;; user interface
;;;; themes
;;;;; wombat theme
(use-package emacs
:straight (:type built-in)
:ensure t
:preface
(load-theme 'wombat))
;;;;; default-text-scale
;; easily adjust the default font size in all Emacs frames
;; [[https://github.com/purcell/default-text-scale][default-text-scale]]
(use-package default-text-scale
:straight t
:bind (:map sej-mode-map
("C-z +" . default-text-scale-increase)
("C-z -" . default-text-scale-decrease)
("s-r" . default-text-scale-reset))
:config
(setq default-text-scale-amount 20))
;;;; frames
;;;;; frame
;; built-in frame package
(use-package frame
:straight (:type built-in)
:bind (:map sej-mode-map
("s-4" . dired-other-frame)
("s-5" . make-frame-command)
("s-6" . delete-other-frames)
("s-w" . delete-frame)
("C-x w" . delete-frame)
("C-z <up>" . sej/frame-resize-full)
("H-C-j" . sej/frame-resize-full)
("C-z <left>" . sej/frame-resize-l)
("H-C-h" . sej/frame-resize-l)
("<A-M-left>" . sej/frame-resize-l)
("C-z <S-left>" . sej/frame-resize-l2)
("H-C-S-h" . sej/frame-resize-l2)
("C-z <right>" . sej/frame-resize-r)
("H-C-l" . sej/frame-resize-r)
("<A-M-right>" . sej/frame-resize-r)
("C-z <S-right>" . sej/frame-resize-r2)
("H-C-S-l" . sej/frame-resize-r2)
("H-C-f" . toggle-frame-fullscreen)
("C-z F" . toggle-frame-fullscreen)
("A-M-m" . sej/frame-recentre)
("C-z m" . sej/frame-recentre))
:init
(setq window-divider-default-places t
window-divider-default-bottom-width 1
window-divider-default-right-width 1
frame-title-format '("Emacs - %b")
icon-title-format frame-title-format
frame-resize-pixelwise t
)
(blink-cursor-mode -1)
(unless (display-graphic-p)
(menu-bar-mode -1))
;; Don't open a file in a new frame
(when (boundp 'ns-pop-up-frames)
(setq ns-pop-up-frames nil))
;; Resize frame to left half after startup
(if (display-graphic-p)
(add-hook 'emacs-startup-hook 'sej/frame-resize-l) )
;;;;;; mac specific frame settings
;; - matching dark/light modes and for hiding
;; - https://github.com/purcell/ns-auto-titlebar
(when sys/mac-x-p
(use-package ns-auto-titlebar
:config
(add-to-list 'default-frame-alist '(ns-appearance . dark))
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-hook 'after-load-theme-hook
(lambda ()
(let ((bg (frame-parameter nil 'background-mode)))
(set-frame-parameter nil 'ns-appearance bg)
(setcdr (assq 'ns-appearance default-frame-alist) bg))))
(ns-auto-titlebar-mode))
(if (boundp 'mac-carbon-version-string) ; mac-ports or ns emacs?
(progn
(define-key sej-mode-map (kbd "s-h") (lambda () (interactive) (mac-send-action 'hide)))
)
(progn
(define-key sej-mode-map (kbd "s-h") 'ns-do-hide-emacs)
)
)
)
(defun sej/frame-resize-full ()
"Set frame full height and 1/2 wide, position at screen left."
(interactive)
(set-frame-position (selected-frame) 0 0)
(set-frame-size (selected-frame) (- (display-pixel-width) (if sys/macp (eval 13) (eval 25)))
(- (display-pixel-height) (- (frame-outer-height) (frame-inner-height))) 1))
(defun sej/frame-resize-l ()
"Set frame full height and 1/2 wide, position at screen left."
(interactive)
(set-frame-position (selected-frame) 0 0)
(set-frame-size (selected-frame) (- (truncate (/ (display-pixel-width) 2)) 0)
(- (display-pixel-height) (- (frame-outer-height) (frame-inner-height))) 1))
(defun sej/frame-resize-l2 ()
"Set frame full height and 1/2 wide, position at left hand screen in extended monitor display assumes monitors are same resolution."
(interactive)
(set-frame-position (selected-frame) 0 0)
(set-frame-size (selected-frame) (- (truncate (/ (display-pixel-width) 4)) 0)
(- (display-pixel-height) (- (frame-outer-height) (frame-inner-height))) 1) )
(defun sej/frame-resize-r ()
"Set frame full height and 1/2 wide, position at screen right."
(interactive)
(set-frame-position (selected-frame) (- (truncate (/ (display-pixel-width) 2)) 0) 0)
(set-frame-size (selected-frame) (- (truncate (/ (display-pixel-width) 2)) 0)
(- (display-pixel-height) (- (frame-outer-height) (frame-inner-height))) 1) )
(defun sej/frame-resize-r2 ()
"Set frame full height and 1/2 wide, position at screen right of left hand screen in extended monitor display assumes monitors are same resolution."
(interactive)
(set-frame-position (selected-frame) (- (/ (display-pixel-width) 2) (frame-pixel-width)) 0)
(set-frame-size (selected-frame) (- (truncate (/ (display-pixel-width) 4)) 0)
(- (display-pixel-height) (- (frame-outer-height) (frame-inner-height))) 1) )
(when sys/mac-x-p
(setq ns-use-native-fullscreen nil))
(defun sej/frame-recentre (&optional frame)
"Center FRAME on the screen.
FRAME can be a frame name, a terminal name, or a frame.
If FRAME is omitted or nil, use currently selected frame."
(interactive)
(unless (eq 'maximised (frame-parameter nil 'fullscreen))