kkk-initial.el 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. ;;; kkk-initial.el --- Initial config of Emacs -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023 Vinicius Teshima <vini.tes@pm.me>
  3. ;; Author: Vinicius Teshima <vini.tes@pm.me>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; This will set the basic config of Emacs
  16. ;;; Code:
  17. (defgroup kkk-initial nil
  18. "Initial Tweaks to Emacs."
  19. :group 'kkk-emacs)
  20. (defun kkk--display-startup-time()
  21. "Display the time it took for Emacs to start."
  22. (message "Emacs loaded in %s with %d garbage collection."
  23. (format "%.2f seconds"
  24. (float-time
  25. (time-subtract after-init-time before-init-time)))
  26. gcs-done))
  27. (add-hook 'emacs-startup-hook #'kkk--display-startup-time)
  28. ;; This is the default
  29. ;; (setq-default indent-tabs-mode t) ; Use Tabs as indentation
  30. ;; (setq-default tab-width 8) ; Setting the size of Tabs
  31. (setq inhibit-startup-message t) ; Disable Startup Message
  32. (setq visible-bell t) ; Use Visible Bell instead of Audible
  33. (setq use-dialog-box nil) ; Don't use gtk dialog box
  34. (menu-bar-mode -1) ; Disable Menu Bar
  35. ;; Disable various things if is in an Graphical Environment
  36. (when (display-graphic-p)
  37. (scroll-bar-mode -1) ; Removing scrollbar
  38. (tool-bar-mode -1)
  39. (tooltip-mode -1)
  40. (set-fringe-mode 10) ; Sets the fringe size to 10px
  41. )
  42. (global-display-fill-column-indicator-mode 't)
  43. (setq-default fill-column 80)
  44. ;; Auto Revert Mode:
  45. (require 'autorevert)
  46. (global-auto-revert-mode t)
  47. (setq global-auto-revert-non-file-buffers 't)
  48. ;; Numbered Lines:
  49. (require 'kkk-linenumbers)
  50. (setq kkk-linenumbers-global-modes '(not
  51. term-mode eshell-mode vterm-mode
  52. magit-status-mode magit-revision-mode
  53. magit-diff-mode magit-log-mode
  54. magit-blob-mode magit-refs-mode
  55. magit-blame-mode eww-mode
  56. help-mode helpful-mode))
  57. (setq kkk-linenumbers-type 'visual)
  58. (global-kkk-linenumbers-mode t)
  59. ;; Whitespace Mode:
  60. (require 'kkk-whitespace)
  61. (setq kkk-whitespace-global-modes '(not
  62. term-mode shell-mode eshell-mode vterm-mode
  63. magit-status-mode magit-revision-mode
  64. magit-diff-mode magit-log-mode
  65. magit-blob-mode magit-refs-mode
  66. magit-log-select-mode Man-mode
  67. magit-blame-mode eww-mode Custom-Mode
  68. help-mode helpful-mode Buffer-menu-mode
  69. compilation-mode vc-mode vc-dir-mode
  70. notmuch-search-mode notmuch-hello-mode
  71. notmuch-show-mode gud-mode grep-mode
  72. flycheck-error-list-mode dired-mode
  73. xref--xref-buffer-mode))
  74. (setq whitespace-style '(face tabs spaces trailing lines-tail space-before-tab
  75. newline indentation empty space-after-tab
  76. space-mark tab-mark newline-mark
  77. missing-newline-at-eof))
  78. ;;; To be only ascii
  79. ;; (setq whitespace-display-mappings
  80. ;; '((space-mark ?\s [?.] [183]) (space-mark 160 [164] [95])
  81. ;; (newline-mark ?\n [?$ ?\n]) (tab-mark ?\t [?> ?\t])))
  82. (global-kkk-whitespace-mode t)
  83. (setq tab-bar-close-button nil)
  84. (setq tab-bar-new-button-show nil)
  85. ;; (setq max-lisp-eval-depth (* 1024 8)) ; Increase the eval depth
  86. (electric-pair-mode t)
  87. (show-paren-mode t)
  88. (setq show-paren-style 'mixed)
  89. (column-number-mode t)
  90. (display-battery-mode t)
  91. (savehist-mode t)
  92. (add-hook 'find-file-hook #'auto-insert)
  93. (add-hook 'prog-mode #'glasses-mode)
  94. (setq auth-source-save-behavior nil)
  95. (when (display-graphic-p)
  96. (require 'kkk-font)
  97. ;; (setq kkk-font-default-font "Comic Mono")
  98. (setq kkk-font-default-font "Unifont")
  99. (setq kkk-font-fixed-font "Unifont")
  100. (setq kkk-font-variable-font "Unifont")
  101. (when (string= (system-name) "i7.dp.lat")
  102. (setq kkk-font-default-font-size 105))
  103. (add-hook 'emacs-startup-hook #'kkk-font-set)
  104. (add-hook 'ef-themes-post-load-hook #'kkk-font-set)
  105. )
  106. (load-theme 'modus-vivendi)
  107. (require 'kkk-eshell)
  108. (require 'kkk-keepclean)
  109. ;; (require 'kkk-package)
  110. ;; (require 'kkk-exwm)
  111. ;; (require 'kkk-killbuffer)
  112. (require 'kkk-windowsize)
  113. (require 'kkk-abbrev)
  114. ;; Setting up to use tree-sitter by default. Stolen from:
  115. ;; https://www.masteringemacs.org/article/how-to-get-started-tree-sitter
  116. ;; (setq major-mode-remap-alist
  117. ;; '((yaml-mode . yaml-ts-mode)
  118. ;; (bash-mode . bash-ts-mode)
  119. ;; (js2-mode . js-ts-mode)
  120. ;; (typescript-mode . typescript-ts-mode)
  121. ;; (json-mode . json-ts-mode)
  122. ;; (css-mode . css-ts-mode)
  123. ;; (python-mode . python-ts-mode)))
  124. (require 'kkk-scratch)
  125. (global-unset-key (kbd "C-x s"))
  126. (global-set-key (kbd "C-x s b") #'kkk-scratch-buffer-dwim)
  127. (global-set-key (kbd "C-x s x v") #'kkk-scratch-vterm-dwim)
  128. (global-set-key (kbd "C-x s x e") #'kkk-scratch-eshell-dwim)
  129. (global-set-key (kbd "<escape>") #'keyboard-escape-quit)
  130. (global-set-key (kbd "C-x m") #'man)
  131. (global-set-key (kbd "M-p") #'isearch-ring-retreat)
  132. (global-set-key (kbd "M-n") #'isearch-ring-advance)
  133. (global-set-key (kbd "C-t") #'transpose-chars)
  134. (defun kkk--pre-angle-brackets (base extra-string)
  135. "Generate an uniquify name. <EXTRA-STRING> BASE."
  136. (setq tmp extra-string)
  137. (concat "<" (mapconcat #'identity extra-string "/") ">" base))
  138. (setq uniquify-buffer-name-style #'kkk--pre-angle-brackets)
  139. (setq reb-re-syntax 'rx)
  140. ;; (defconst kkk-gomode-dir
  141. ;; (locate-user-emacs-file "gitrepos/go-mode.el")
  142. ;; ".")
  143. ;; (add-to-list 'load-path kkk-gomode-dir)
  144. ;; (autoload 'go-mode "go-mode" nil t)
  145. ;; (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  146. ;; (defconst kkk-reformatter-dir
  147. ;; (locate-user-emacs-file "gitrepos/emacs-reformatter")
  148. ;; ".")
  149. ;; (add-to-list 'load-path kkk-reformatter-dir)
  150. ;; (require 'reformatter)
  151. ;; (defconst kkk-zigmode-dir
  152. ;; (locate-user-emacs-file "gitrepos/zig-mode")
  153. ;; ".")
  154. ;; (add-to-list 'load-path kkk-zigmode-dir)
  155. ;; (autoload 'zig-mode "zig-mode" nil t)
  156. ;; (add-to-list 'auto-mode-alist '("\\.zig\\'" . zig-mode))
  157. ;; (defconst kkk-fasmmode-dir
  158. ;; (locate-user-emacs-file "gitrepos/fasm-mode")
  159. ;; ".")
  160. ;; (add-to-list 'load-path kkk-fasmmode-dir)
  161. ;; (autoload 'fasm-mode "fasm-mode" nil t)
  162. (require 'package)
  163. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
  164. (setq package-selected-packages '(helpful ##))
  165. (global-set-key (kbd "C-h f") #'helpful-callable)
  166. (global-set-key (kbd "C-h v") #'helpful-variable)
  167. (global-set-key (kbd "C-h k") #'helpful-key)
  168. (global-set-key (kbd "C-h x") #'helpful-command)
  169. (fido-mode 1)
  170. (require 'ispell)
  171. (setq ispell-program-name "aspell")
  172. (require 'flyspell)
  173. (setq flyspell-issue-message-flag nil)
  174. (global-set-key (kbd "M-o") #'complete-tag)
  175. ;;(global-set-key (kbd "M-/") #'hippie-expand)
  176. (global-set-key (kbd "M-/") #'dabbrev-expand)
  177. (global-set-key (kbd "C-j") #'join-line)
  178. (global-set-key (kbd "C-%") #'xref-find-references-and-replace)
  179. (setq c-default-style
  180. '((java-mode . "java") (awk-mode . "awk") (other . "linux")))
  181. (global-subword-mode +1)
  182. ;; (hs-minor-mode +1)
  183. (defun narrow-clone(&optional DISPLAY-FLAG)
  184. (interactive)
  185. (let ((name "Unknown")
  186. (line_str (thing-at-point 'line))
  187. (call_start (point))
  188. (start (point-min))
  189. (end (point-max))
  190. (new_buf nil))
  191. (save-excursion
  192. ;; DoWhile
  193. (while
  194. (progn
  195. (forward-line -1)
  196. (setq line_str (thing-at-point 'line))
  197. (and (not (string-prefix-p "//== " line_str))
  198. (/= (point-min) (point)))
  199. )
  200. )
  201. (forward-line 1)
  202. (setq start (point))
  203. )
  204. (when (string-prefix-p "//== " line_str)
  205. (setq name (string-trim (cadr (string-split line_str " "))))
  206. )
  207. (save-excursion
  208. (forward-line 1)
  209. (setq line_str (thing-at-point 'line))
  210. (while (and (not (string-prefix-p "//== " line_str))
  211. (/= (point-max) (point)))
  212. (forward-line 1)
  213. (setq line_str (thing-at-point 'line))
  214. )
  215. (setq end (point))
  216. )
  217. (setq new_buf (clone-indirect-buffer name nil))
  218. (save-excursion
  219. (set-buffer new_buf)
  220. (narrow-to-region start end)
  221. )
  222. (when (not DISPLAY-FLAG)
  223. (switch-to-buffer new_buf))
  224. end
  225. )
  226. )
  227. (defun narrow-clone-buffer()
  228. (interactive)
  229. (goto-char (point-min))
  230. (let ((end (narrow-clone t)))
  231. (while (/= (point-max) end)
  232. (forward-line 1)
  233. (setq end (narrow-clone t))
  234. )
  235. )
  236. )
  237. ;; Stolen from (http://endlessparentheses.com/ansi-colors-in-the-compilation-buffer-output.html)
  238. (require 'ansi-color)
  239. (defun endless/colorize-compilation ()
  240. "Colorize from `compilation-filter-start' to `point'."
  241. (let ((inhibit-read-only t))
  242. (ansi-color-apply-on-region
  243. compilation-filter-start (point))))
  244. (add-hook 'compilation-filter-hook
  245. #'endless/colorize-compilation)
  246. ;; Stolen from (https://oleksandrmanzyuk.wordpress.com/2011/11/05/better-emacs-shell-part-i/)
  247. (defun regexp-alternatives (regexps)
  248. "Return the alternation of a list of regexps."
  249. (mapconcat (lambda (regexp)
  250. (concat "\\(?:" regexp "\\)"))
  251. regexps "\\|"))
  252. (defvar non-sgr-control-sequence-regexp nil
  253. "Regexp that matches non-SGR control sequences.")
  254. (setq non-sgr-control-sequence-regexp
  255. (regexp-alternatives
  256. '(;; icon name escape sequences
  257. "\033\\][0-2];.*?\007"
  258. ;; non-SGR CSI escape sequences
  259. "\033\\[\\??[0-9;]*[^0-9;m]"
  260. ;; noop
  261. "\012\033\\[2K\033\\[1F"
  262. )))
  263. (defun filter-non-sgr-control-sequences-in-region (begin end)
  264. (save-excursion
  265. (goto-char begin)
  266. (while (re-search-forward
  267. non-sgr-control-sequence-regexp end t)
  268. (replace-match ""))))
  269. (defun filter-non-sgr-control-sequences-in-output (ignored)
  270. (let ((start-marker
  271. (or comint-last-output-start
  272. (point-min-marker)))
  273. (end-marker
  274. (process-mark
  275. (get-buffer-process (current-buffer)))))
  276. (filter-non-sgr-control-sequences-in-region
  277. start-marker
  278. end-marker)))
  279. (add-hook 'comint-output-filter-functions
  280. 'filter-non-sgr-control-sequences-in-output)
  281. (require 'hare-mode)
  282. (provide 'kkk-initial)
  283. ;;; kkk-initial.el ends here