2022-08-06 17:32:27 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; start emacs server (daemon) via real client so org-mode and other 'workspaces' can be setup as faux daemonized emacs
2022-08-11 15:38:46 +00:00
; (server-start)
2022-08-06 17:32:27 +00:00
2022-04-22 04:25:29 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Packages related
2022-04-26 12:06:30 +00:00
( require 'package )
2022-04-22 04:48:52 +00:00
( add-to-list 'package-archives ' ( " melpa " . " https://melpa.org/packages/ " ) t ) ; this goes in chemacs2 init -- DO NOT UNCOMMENT
( package-initialize ) ; this goes in chemacs2 init -- DO NOT UNCOMMENT
2022-04-22 04:25:29 +00:00
( add-to-list 'package-selected-packages
2022-08-28 17:36:06 +00:00
' ( popwin dired-single diredfl xclip doominhibitinhibit-modeline magit helpful helm helm-org helm-ls-git projectile helm-projectile dired-rainbow dired-rainbow-listing dired-single dash s origami persp-mode persp-mode-projectile-bridge modus-themes transpose-frame use-package )
2022-04-22 04:25:29 +00:00
)
( require 'use-package )
2022-04-22 21:03:15 +00:00
; helper functions
( require 'subr-x )
( setq kmn/is-termux
( string-suffix-p " Android " ( string-trim ( shell-command-to-string " uname -a " ) ) ) )
2022-04-23 19:35:42 +00:00
; ensure elisp plugins are compiled
( require 'dash )
( require 'f )
( defun was-compiled-p ( path )
" Does the directory at PATH contain any .elc files? "
( --any-p ( f-ext? it " elc " ) ( f-files path ) ) )
( defun ensure-packages-compiled ( )
" If any packages installed with package.el aren't compiled yet, compile them. "
( --each ( f-directories package-user-dir )
( unless ( was-compiled-p it )
( byte-recompile-directory it 0 ) ) ) )
( ensure-packages-compiled )
2022-06-02 18:33:30 +00:00
( unless ( was-compiled-p " ~/.emacs.d.profiles/common " )
( byte-recompile-directory " ~/.emacs.d.profiles/common " 0 ) )
2022-04-23 17:10:05 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; backups
( defconst kmn/backup-dir
( expand-file-name " backups/ " user-emacs-directory ) )
( unless ( file-exists-p kmn/backup-dir )
( make-directory kmn/backup-dir ) )
( setq backup-directory-alist ` ( ( " .* " . , kmn/backup-dir ) ) )
( setq auto-save-list-file-prefix kmn/backup-dir )
( setq auto-save-file-name-transforms
` ( ( " \\ (?:[^/]*/ \\ )* \\ (.* \\ ) " , ( concat kmn/backup-dir " \\ 1 " ) t ) ) )
( setq backup-by-copying t ) ; safest form of backup file creation
; Config backups so we have *more*, not less
( setq delete-old-versions t
kept-new-versions 1
kept-old-versions 3
version-control t
)
2022-04-22 21:03:15 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; dired adjustments
2022-08-26 16:48:45 +00:00
( with-eval-after-load 'dired
( require 'dired-x )
;; Set dired-x global variables here. For example:
;; (setq dired-x-hands-off-my-keys nil)
)
2022-04-22 21:03:15 +00:00
( require 'dired-single )
( defun my-dired-init ( )
" Bunch of stuff to run for dired, either immediately or when it's
loaded. "
;; <add other stuff here>
( define-key dired-mode-map [ remap dired-find-file ]
'dired-single-buffer )
( define-key dired-mode-map [ remap dired-mouse-find-file-other-window ]
'dired-single-buffer-mouse )
( define-key dired-mode-map [ remap dired-up-directory ]
'dired-single-up-directory ) )
;; if dired's already loaded, then the keymap will be bound
( if ( boundp 'dired-mode-map )
;; we're good to go; just add our bindings
( my-dired-init )
;; it's not loaded yet, so add our bindings to the load-hook
( add-hook 'dired-load-hook 'my-dired-init ) )
; icons / colors / line tunes
( add-hook 'dired-mode-hook
( lambda ( )
( interactive )
2022-08-26 16:04:43 +00:00
( all-the-icons-dired-mode 1 )
2022-04-22 21:03:15 +00:00
( hl-line-mode 1 ) ) )
2022-08-26 16:46:14 +00:00
( use-package diredfl
:commands diredfl-global-mode
:init
( diredfl-global-mode ) )
2022-04-22 21:03:15 +00:00
2022-04-22 04:25:29 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2022-04-22 21:03:15 +00:00
; origami config
( use-package origami
:demand
:config
( define-prefix-command 'origami-mode-map )
( define-key ctl-x-map ( kbd " z " ) 'origami-mode-map )
( global-origami-mode )
:bind
( :map origami-mode-map
( " o " . origami-open-node )
( " O " . origami-open-node-recursively )
( " c " . origami-close-node )
( " C " . origami-close-node-recursively )
( " a " . origami-toggle-node )
( " t " . origami-recursively-toggle-node )
( " R " . origami-open-all-nodes )
( " M " . origami-close-all-nodes )
( " v " . origami-show-only-node )
( " k " . origami-previous-fold )
( " j " . origami-forward-fold )
( " x " . origami-reset ) ) )
2022-08-28 16:01:42 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; modern home/end via C-a and C-e
( defun my--smart-beginning-of-line ( )
" Move point to `beginning-of-line' . If repeat command it cycle
position between ` back-to-indentation ' and ` beginning-of-line '. "
( interactive " ^ " )
( if ( eq last-command 'my--smart-beginning-of-line )
( if ( = ( line-beginning-position ) ( point ) )
( back-to-indentation )
( beginning-of-line ) )
( back-to-indentation ) ) )
( defun my--smart-end-of-line ( )
" Move point to `end-of-line' . If repeat command it cycle
position between last non-whitespace and ` end-of-line '. "
( interactive " ^ " )
( if ( and ( eq last-command 'my--smart-end-of-line )
( = ( line-end-position ) ( point ) ) )
( skip-syntax-backward " " ( line-beginning-position ) )
( end-of-line ) ) )
( defun kill-other-buffers ( )
" Kill all buffers but the current one. Don't mess with special buffers. "
( interactive )
( dolist ( buffer ( buffer-list ) )
( unless ( or ( eql buffer ( current-buffer ) ) ( not ( buffer-file-name buffer ) ) )
( kill-buffer buffer ) ) ) )
2022-04-22 04:25:29 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Setup global keys
2022-04-23 21:36:44 +00:00
( require 'transpose-frame )
2022-04-22 04:25:29 +00:00
( cua-mode 1 )
2022-04-23 17:18:39 +00:00
( windmove-default-keybindings 'meta )
2022-04-22 04:25:29 +00:00
( global-set-key ( kbd " <escape> " ) 'keyboard-escape-quit )
2022-04-23 21:36:44 +00:00
( global-set-key ( kbd " M-m " ) 'menu-bar-open )
2022-04-22 04:25:29 +00:00
( global-set-key ( kbd " <M-f4> " ) 'delete-frame )
( global-set-key ( kbd " C-x C-z " ) nil )
2022-04-23 21:36:44 +00:00
( global-set-key ( kbd " C-g " ) 'goto-line )
( global-set-key ( kbd " C-c u " ) 'toggle-truncate-lines )
2022-08-26 16:04:43 +00:00
( global-set-key ( kbd " C-o " ) 'helm-find-files )
2022-04-23 15:56:10 +00:00
( global-set-key ( kbd " C-k " ) 'dired )
2022-08-28 16:01:42 +00:00
( global-set-key ( kbd " C-a " ) 'my--smart-beginning-of-line )
( global-set-key ( kbd " C-e " ) 'my--smart-end-of-line )
2022-04-23 14:21:53 +00:00
( global-set-key ( kbd " C-c w " )
( lambda ( )
( interactive )
( whitespace-mode )
( whitespace-newline-mode )
)
)
2022-04-22 04:25:29 +00:00
2022-04-23 21:36:44 +00:00
( global-set-key ( kbd " M-k " ) 'delete-window )
( global-set-key ( kbd " M- \" " ) 'split-window-below )
( global-set-key ( kbd " M-# " ) 'split-window-right )
( global-set-key ( kbd " M-. " ) 'rotate-frame-clockwise )
( global-set-key ( kbd " M-, " ) 'rotate-frame-anticlockwise )
2022-04-22 04:25:29 +00:00
;; Lookup the current symbol at point. C-c C-d is a common keybinding
;; for this in lisp modes.
2022-04-23 21:36:44 +00:00
( global-set-key ( kbd " M-h " ) 'describe-bindings )
2022-04-22 04:25:29 +00:00
( global-set-key ( kbd " C-c C-d " ) #' helpful-at-point )
2022-04-23 15:49:04 +00:00
; more vscode/gui styled find/replace
( defun query-replace-region-or-from-top ( )
" If marked, query-replace for the region, else for the whole buffer (start from the top) "
( interactive )
( progn
( let ( ( orig-point ( point ) ) )
( if ( use-region-p )
( call-interactively 'query-replace )
( save-excursion
( goto-char ( point-min ) )
( call-interactively 'query-replace ) ) )
( message " Back to old point. " )
( goto-char orig-point ) ) ) )
( bind-key* " M-% " 'query-replace-region-or-from-top )
( global-set-key ( kbd " C-h " ) 'query-replace-region-or-from-top )
; more vscode/gui styled find/replace
( global-set-key ( kbd " C-s " ) 'isearch-forward )
( global-set-key ( kbd " C-f " ) 'isearch-forward )
2022-04-22 04:25:29 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set some global config
( setq inhibit-splash-screen t ) ; why do you need to tell me things i know by default
2022-08-28 15:14:22 +00:00
( setq inhibit-startup-screen t )
( setq inhibit-startup-echo-area-message t )
2022-04-22 04:25:29 +00:00
( setq-default tab-width 4 ) ; sanity!
( electric-indent-mode 0 ) ; return should NOT fuck with the indentation of the previous line
2022-04-23 16:14:37 +00:00
2022-04-22 04:25:29 +00:00
;; make typing delete/overwrites selected text
( delete-selection-mode 1 )
2022-04-23 16:14:37 +00:00
2022-04-22 04:25:29 +00:00
;; UTF-8 as default encoding
( set-default-coding-systems 'utf-8 )
( set-language-environment " UTF-8 " )
( set-default-coding-systems 'utf-8-unix )
2022-08-25 17:42:20 +00:00
; auto revert when files/dired changes
( setq global-auto-revert-non-file-buffers t )
( global-auto-revert-mode 1 )
2022-08-26 17:14:12 +00:00
; Clipboard integration
( use-package xclip :config ( xclip-mode 1 ) )
2022-08-28 15:14:22 +00:00
;; use y or n instead of yes or not
( fset 'yes-or-no-p 'y-or-n-p )
2022-04-22 04:25:29 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; set font for emoji -- DOES NOT WORK ON MOBILE
( when ( eq system-type 'windows-nt )
( set-fontset-font
t
' ( #x1f300 . #x1fad0 )
( cond
( ( member " Noto Color Emoji " ( font-family-list ) ) " Noto Color Emoji " )
( ( member " Noto Emoji " ( font-family-list ) ) " Noto Emoji " )
( ( member " Segoe UI Emoji " ( font-family-list ) ) " Segoe UI Emoji " )
( ( member " Symbola " ( font-family-list ) ) " Symbola " )
( ( member " Apple Color Emoji " ( font-family-list ) ) " Apple Color Emoji " ) )
;; Apple Color Emoji should be before Symbola, but Richard Stallman skum disabled it.
;; GNU Emacs Removes Color Emoji Support on the Mac
;; http://ergoemacs.org/misc/emacs_macos_emoji.html
;;
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; line numbers
; find major mode : M-x eval-expression [enter] major-mode
( require 'display-line-numbers )
( defcustom display-line-numbers-exempt-modes ' ( org-mode org-agenda-mode )
" Major modes on which to disable the linum mode, exempts them from global requirement "
:group 'display-line-numbers
:type 'list
:version " green " )
( defun display-line-numbers--turn-on ( )
" turn on line numbers but excempting certain majore modes defined in `display-line-numbers-exempt-modes' "
( if ( and
( not ( member major-mode display-line-numbers-exempt-modes ) )
( not ( minibufferp ) ) )
( display-line-numbers-mode ) ) )
( global-display-line-numbers-mode )
2022-04-23 14:21:53 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; whitespace
( progn
;; Make whitespace-mode with very basic background coloring for whitespaces.
;; http://xahlee.info/emacs/emacs/whitespace-mode.html
( setq whitespace-style ( quote ( face spaces tabs newline space-mark tab-mark newline-mark ) ) )
;; Make whitespace-mode and whitespace-newline-mode use “¶” for end of line char and “▷” for tab.
( setq whitespace-display-mappings
;; all numbers are unicode codepoint in decimal. e.g. (insert-char 182 1)
' (
( space-mark 32 [ 183 ] [ 46 ] ) ; SPACE 32 「 」, 183 MIDDLE DOT 「·」, 46 FULL STOP 「.」
( newline-mark 10 [ 8629 10 ] ) ; LINE FEED,
( tab-mark 9 [ 8594 9 ] [ 92 9 ] ) ; tab
) ) )
2022-04-22 04:25:29 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; modus-themes setup and enable
( use-package modus-themes
:ensure
:init
( setq modus-themes-region ' ( no-extend )
modus-themes-fringes 'subtle
modus-themes-scale-headings t
)
( modus-themes-load-themes )
:config
( modus-themes-load-vivendi )
)
2022-04-25 19:23:09 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; helm
( setq completion-styles ' ( flex ) )
2022-04-25 19:54:47 +00:00
2022-04-25 19:23:09 +00:00
( require 'helm-config )
2022-04-25 19:54:47 +00:00
( require 'helm-color )
( require 'helm-ls-git )
( require 'helm-org )
2022-04-25 19:23:09 +00:00
( helm-mode 1 )
2022-04-25 19:54:47 +00:00
( helm-autoresize-mode 1 )
2022-08-28 15:25:43 +00:00
( setq helm-display-header-line nil
2022-08-28 15:56:55 +00:00
helm-autoresize-max-height 30
helm-autoresize-min-height 30 )
2022-08-28 15:25:43 +00:00
( setq helm-split-window-in-side-p t ; open helm buffer inside current window, not occupy whole other window
helm-ff-file-name-history-use-recentf t
helm-echo-input-in-header-line t )
2022-04-25 19:54:47 +00:00
( global-set-key ( kbd " C-x C-d " ) 'helm-browse-project )
2022-08-26 15:07:27 +00:00
( global-set-key ( kbd " C-x b " ) 'list-buffers )
2022-04-25 19:23:09 +00:00
( define-key global-map [ remap find-file ] 'helm-find-files )
( define-key global-map [ remap occur ] 'helm-occur )
( define-key global-map [ remap list-buffers ] 'helm-buffers-list )
( define-key global-map [ remap dabbrev-expand ] 'helm-dabbrev )
( define-key global-map [ remap execute-extended-command ] 'helm-M-x )
( define-key global-map [ remap apropos-command ] 'helm-apropos )
( unless ( boundp 'completion-in-region-function )
( define-key lisp-interaction-mode-map [ remap completion-at-point ] 'helm-lisp-completion-at-point )
( define-key emacs-lisp-mode-map [ remap completion-at-point ] 'helm-lisp-completion-at-point ) )
( add-hook 'kill-emacs-hook #' ( lambda ( ) ( and ( file-exists-p " $CONF_FILE " ) ( delete-file " $CONF_FILE " ) ) ) )
2022-04-25 19:54:47 +00:00
( add-to-list 'helm-completing-read-handlers-alist ' ( org-capture . helm-org-completing-read-tags ) )
( add-to-list 'helm-completing-read-handlers-alist ' ( org-set-tags . helm-org-completing-read-tags ) )
2022-04-25 22:41:50 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; persp-mode
( setq persp-auto-resume-time 0.25 )
( setq persp-add-buffer-on-find-file nil )
( with-eval-after-load " persp-mode-autoloads "
( setq wg-morph-on nil ) ;; switch off animation
( setq persp-autokill-buffer-on-remove 'kill-weak )
( add-hook 'window-setup-hook #' ( lambda ( ) ( persp-mode 1 ) ) ) )
2022-04-25 20:20:00 +00:00
2022-04-25 23:11:06 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; diminish config
; https://melpa.org/#/manage-minor-mode
; M-x: manage-minor-mode
;
; M-x: describe-mode
2022-04-26 12:32:27 +00:00
;(require 'diminish)
;(diminish 'rainbow-mode) ; Hide lighter from mode-line
;(diminish 'org-habit) ; im well aware i have org-habit enabled globally. thanks
;(diminish 'helm-mode)
;(diminish 'eldoc-mode)
2022-04-25 23:11:06 +00:00
2022-04-25 23:25:25 +00:00
;
; doom-modeline
( require 'doom-modeline )
( setq all-the-icons-color-icons nil )
( setq find-file-visit-truename t )
( doom-modeline-mode 1 )
2022-04-25 18:43:48 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; flyspell
2022-08-26 00:05:52 +00:00
( require 'flyspell )
( setenv " LANG " " en_US " )
( setq ispell-program-name " hunspell " )
( setq ispell-dictionary " en_US " )
( use-package flyspell :demand t
:config
( use-package
flyspell-correct-helm )
2022-08-26 13:45:51 +00:00
2022-08-26 00:05:52 +00:00
( defun flyspell-most-modes ( )
2022-08-26 13:45:51 +00:00
( add-hook 'text-mode-hook ( lambda ( ) ( flyspell-mode 1 ) ) )
( add-hook 'prog-mode-hook ( lambda ( ) ( flyspell-mode 1 ) ) )
2022-08-26 19:58:28 +00:00
( dolist ( hook ' ( change-log-mode-hook log-edit-mode-hook org-agenda ) )
2022-08-26 00:05:52 +00:00
( add-hook hook ( lambda ( )
( flyspell-mode -1 ) ) ) ) )
( flyspell-most-modes )
)
( defun flyspell-on-for-buffer-type ( )
" Enable Flyspell appropriately for the major mode of the current buffer. Uses `flyspell-prog-mode' for modes derived from `prog-mode' , so only strings and comments get checked. All other buffers get `flyspell-mode' to check all text. If flyspell is already enabled, does nothing. "
( interactive )
( if ( not ( symbol-value flyspell-mode ) ) ; if not already on
( progn
( if ( derived-mode-p 'prog-mode )
( progn
( message " Flyspell on (code) " )
( flyspell-prog-mode ) )
;; else
( progn
( message " Flyspell on (text) " )
( flyspell-mode 1 ) ) )
;; I tried putting (flyspell-buffer) here but it didn't seem to work
) ) )
( defun flyspell-toggle ( )
" Turn Flyspell on if it is off, or off if it is on. When turning on, it uses `flyspell-on-for-buffer-type' so code-vs-text is handled appropriately. "
( interactive )
( if ( symbol-value flyspell-mode )
( progn ; flyspell is on, t it off
( message " Flyspell off " )
( flyspell-mode -1 ) )
; else - flyspell is off, turn it on
( flyspell-on-for-buffer-type ) ) )
; flyspell keyboard shortcuts
( global-set-key ( kbd " C-x y " ) 'flyspell-toggle )
( global-set-key ( kbd " C-x w " ) 'flyspell-correct-wrapper )
2022-08-28 15:56:55 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; golden-ratio
( load " ~/.emacs.d.profiles/common/golden-ratio.el " )
( require 'golden-ratio )
( setq golden-ratio--value 1.618 ) ; default: 1.618
;; add ace-window jump to trigger commands
;;(nconc golden-ratio-extra-commands '(ace-window))
;(setq golden-ratio-exclude-modes '(org-mode))
;;(setq golden-ratio-auto-scale t)
( golden-ratio-mode t )
2022-08-28 17:36:06 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; popup windows
( require 'popwin )
( popwin-mode 1 )
( global-set-key ( kbd " C-w " ) popwin:keymap )
( push " *scratch* " popwin:special-display-config )