Browse Source

Switch to spaces in some languages, experimentation

* Some modes now default to spaces instead of tabs (sorry for any trouble...)
* Experimented with whitespace
* Changed some .el indentation
master
Macoy Madson 2 years ago
parent
commit
38b1adf7e3
  1. 129
      Emacs/core-settings.el
  2. 3
      Emacs/desktop-management.el
  3. 90
      Emacs/packages.el
  4. 6
      Emacs/syntaxes.el
  5. 100
      Emacs/tags-and-autocompletion.el
  6. 44
      Emacs/visual-early.el

129
Emacs/core-settings.el

@ -57,34 +57,34 @@
(interactive)
;; TODO: Make sure dependent buffers aren't broken when this happens!
(setq macoy-buffers-to-kill (list
"*Backtrace*"
"*CTags-out*"
"*Calc Trail*"
"*Calculator*"
"*Codesearch*"
"*Codesearch-Index*"
"*Compile-Log*"
"*Completions*"
"*Diff*"
"*Ediff Registry*"
"*Gimme-checkout*"
"*Gimme-GetLatest*"
"*Help*"
"*Packages*"
"*ag search*"
"*compilation*"
"*log-edit-files*"
"*svn output*"
"*vc-change-log*"
"*vc-diff*"
"*xref*"
"*Macoy-Select-Search*"
"*Occur*"
))
"*Backtrace*"
"*CTags-out*"
"*Calc Trail*"
"*Calculator*"
"*Codesearch*"
"*Codesearch-Index*"
"*Compile-Log*"
"*Completions*"
"*Diff*"
"*Ediff Registry*"
"*Gimme-checkout*"
"*Gimme-GetLatest*"
"*Help*"
"*Packages*"
"*ag search*"
"*compilation*"
"*log-edit-files*"
"*svn output*"
"*vc-change-log*"
"*vc-diff*"
"*xref*"
"*Macoy-Select-Search*"
"*Occur*"
))
(mapcar
(lambda (buffer-to-kill)
(when (get-buffer buffer-to-kill)
(kill-buffer buffer-to-kill)))
(when (get-buffer buffer-to-kill)
(kill-buffer buffer-to-kill)))
macoy-buffers-to-kill))
(defun macoy-bury-buffer-anywhere (buffer-or-name)
@ -94,12 +94,12 @@ and defaults to the current buffer. For example,
(macoy-bury-buffer-anywhere \"*Compile-Log*\")
would dismiss the compile log, if it was visible"
(let ((buffer (window-normalize-buffer buffer-or-name))
;; Handle the "inverted" meaning of the FRAME argument wrt other
;; `window-list-1' based function.
(all-frames t))
;; Handle the "inverted" meaning of the FRAME argument wrt other
;; `window-list-1' based function.
(all-frames t))
(dolist (window (window-list-1 nil nil all-frames))
(when (eq (window-buffer window) buffer)
(switch-to-prev-buffer window)))))
(switch-to-prev-buffer window)))))
;; Store recently opened files so we can easily reopen them
(recentf-mode 1)
@ -127,27 +127,27 @@ would dismiss the compile log, if it was visible"
;; Ido flx settings: make ido have fuzzy sublime-like matching
(when (require 'flx-ido)
(ido-mode 1)
(ido-everywhere 1)
(flx-ido-mode 1)
;; disable ido faces to see flx highlights.
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
)
(ido-mode 1)
(ido-everywhere 1)
(flx-ido-mode 1)
;; disable ido faces to see flx highlights.
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
)
(setq ido-everywhere t)
;; No really, do ido everywhere
(when (require 'ido-completing-read+)
(ido-ubiquitous-mode 1))
(ido-ubiquitous-mode 1))
;; Use ido for recentf file selection
;; From https://masteringemacs.org/article/find-files-faster-recent-files-package
(defun ido-recentf-open ()
"Use `ido-completing-read' to \\[find-file] a recent file"
(interactive)
(find-file (ido-completing-read "Find recent file: " recentf-list))
)
"Use `ido-completing-read' to \\[find-file] a recent file"
(interactive)
(find-file (ido-completing-read "Find recent file: " recentf-list))
)
(global-set-key (kbd "C-S-t") 'ido-recentf-open)
)
@ -161,17 +161,17 @@ would dismiss the compile log, if it was visible"
projectile-globally-ignored-files))
(setq projectile-globally-ignored-directories
(append '("AutoGen"
"3rdparty"
"obj140"
".build"
".cquery_cached_index")
"3rdparty"
"obj140"
".build"
".cquery_cached_index")
projectile-globally-ignored-files))
(projectile-mode 1)
;; Make projectile mode-line more minimal
;; TODO: Make this work based on version!
(defun macoy-projectile-mode-line ()
(format " [%s]" (projectile-project-name)))
(format " [%s]" (projectile-project-name)))
(setq projectile-mode-line-function 'macoy-projectile-mode-line)
;; Older version syntax
;; (setq projectile-mode-line '(:eval (format " [%s]" (projectile-project-name))))
@ -182,9 +182,8 @@ would dismiss the compile log, if it was visible"
(when (require 'simpleclip)
(defun macoy-copy-buffer-filename-to-clipboard ()
(interactive)
(simpleclip-set-contents buffer-file-name)
)
(interactive)
(simpleclip-set-contents buffer-file-name))
)
;; Open file in explorer
@ -202,4 +201,32 @@ would dismiss the compile log, if it was visible"
"Open the path in region."
(interactive)
(when (use-region-p)
(find-file (buffer-substring (region-beginning) (region-end)))))
(find-file (buffer-substring (region-beginning) (region-end)))))
;;
;; Tabs and indentation
;;
;; Delete tabs instead of converting them to spaces
(setq backward-delete-char-untabify-method nil)
;; From https://dougie.io/emacs/indentation (with some modifications
;; Two callable functions for enabling/disabling tabs in Emacs
(defun disable-tabs ()
(interactive)
(setq indent-tabs-mode nil))
(defun enable-tabs ()
(interactive)
;; (local-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq indent-tabs-mode t)
(setq tab-width 4))
;; Hooks to Enable Tabs
(add-hook 'c-mode-hook 'enable-tabs)
(add-hook 'c++-mode-hook 'enable-tabs)
(add-hook 'lua-mode-hook 'enable-tabs)
;; Hooks to Disable Tabs
(add-hook 'lisp-mode-hook 'disable-tabs)
(add-hook 'emacs-lisp-mode-hook 'disable-tabs)
(add-hook 'python-mode-hook 'disable-tabs)

3
Emacs/desktop-management.el

@ -6,6 +6,9 @@
;; care too much about losing our frame configurations so this is okay
(setq desktop-restore-frames nil)
;; Lazy load buffers instead of loading them all at once (which takes too long)
(setq desktop-restore-eager 4)
;; Used to know whether or not to show the last selected desktop at the top of the desktop list
(setq macoy-has-ever-selected-desktop-this-session nil)

90
Emacs/packages.el

@ -17,58 +17,58 @@
;; (package-initialize)
(defun macoy-package-install (package)
(message "Installing %s" package)
(package-install package))
(message "Installing %s" package)
(package-install package))
;; Install uninstalled packages
(let* ((package--builtins nil)
(packages
'(adaptive-wrap
ag
alect-themes
auto-complete
avy
base16-theme
better-defaults
clang-format
darktooth-theme
diminish
dired-narrow
dsvn
engine-mode
expand-region
flx-ido
htmlize
ido-vertical-mode
ido-completing-read+
ivy
ivy-xref
iy-go-to-char
keyfreq
lua-mode
markdown-mode
magit
multiple-cursors
org-jira
org-mru-clock
powerline
projectile
rainbow-mode
simpleclip
smex
smooth-scrolling
sublime-themes
swiper
web-beautify
web-mode
xah-find
yasnippet
zenburn-theme
)))
ag
alect-themes
auto-complete
avy
base16-theme
better-defaults
clang-format
darktooth-theme
diminish
dired-narrow
dsvn
engine-mode
expand-region
flx-ido
htmlize
ido-vertical-mode
ido-completing-read+
ivy
ivy-xref
iy-go-to-char
keyfreq
lua-mode
markdown-mode
magit
multiple-cursors
org-jira
org-mru-clock
powerline
projectile
rainbow-mode
simpleclip
smex
smooth-scrolling
sublime-themes
swiper
web-beautify
web-mode
xah-find
yasnippet
zenburn-theme
)))
(ignore-errors
(message "Checking for packages to install...")
(message "Checking for packages to install...")
(let ((packages (seq-remove 'package-installed-p packages)))
(when packages
(message "Installing packages...")
(message "Installing packages...")
(package-refresh-contents)
(mapc 'macoy-package-install packages)))))

6
Emacs/syntaxes.el

@ -67,3 +67,9 @@
;; Function list
nil
)
(when (require 'lua-mode)
(setq lua-indent-level 4))
(when (require 'smart-tabs-mode
(smart-tabs-insinuate 'c 'c++)))

100
Emacs/tags-and-autocompletion.el

@ -11,9 +11,8 @@
;; Refresh and load tags
;; TODO: Use projectile refresh ctags instead
(if (eq system-type 'gnu/linux)
(setq ctags-path "ctags")
(setq ctags-path "C:/programsMacoy/ctags58/ctags.exe")
)
(setq ctags-path "ctags")
(setq ctags-path "C:/programsMacoy/ctags58/ctags.exe"))
(defun generateTags ()
"Create tags file"
@ -21,31 +20,29 @@
;;(let ((default-directory "F:/CJUNCTIONS/src/")))
(message "Running CTags")
(let ((ctagsProc (start-process "CTags" "*CTags-out*" ctags-path "-e" "-f"
;; Output location
(concat (projectile-project-root) "TAGS")
;; Additional arguments
"--verbose" "--recurse=yes" "--languages=C,C++,Python"
;; Annoyingly there doesn't seem to be wildcard matching for folders (at least
;; not on Windows)
"--exclude=/home/macoy/Development/code/3rdParty/repositories/blender/doc"
;; Includes
(projectile-project-root) ;; HOME_ONLY
;; "F:/CJUNCTIONS/src/Core"
)))
(set-process-sentinel ctagsProc
(lambda (ctagsProc _string)
(call-interactively 'macoy-ido-find-tag-refresh))))
)
;; Output location
(concat (projectile-project-root) "TAGS")
;; Additional arguments
"--verbose" "--recurse=yes" "--languages=C,C++,Python"
;; Annoyingly there doesn't seem to be wildcard matching for folders (at least
;; not on Windows)
"--exclude=/home/macoy/Development/code/3rdParty/repositories/blender/doc"
;; Includes
(projectile-project-root) ;; HOME_ONLY
;; "F:/CJUNCTIONS/src/Core"
)))
(set-process-sentinel ctagsProc
(lambda (ctagsProc _string)
(call-interactively 'macoy-ido-find-tag-refresh)))))
(defun loadTagsFromParent ()
(let ((my-tags-file (locate-dominating-file default-directory "TAGS")))
(when my-tags-file
(message "Loading tags file: %s" my-tags-file)
(visit-tags-table my-tags-file)))
)
(visit-tags-table my-tags-file))))
;; Use Ivy to select xref results
(require 'ivy-xref)
@ -54,11 +51,11 @@
;; This isn't really necessary because attempting a goto definition will automatically do this
;;(global-set-key (kbd "C-<f5>") (lambda () (interactive) (loadTagsFromParent)))
(global-set-key (kbd "C-<f5>")
(lambda ()
(interactive)
;; Note that these are both subprocesses so they will run at the same time
(generateTags)
(macoy-codesearch-index-default)))
(lambda ()
(interactive)
;; Note that these are both subprocesses so they will run at the same time
(generateTags)
(macoy-codesearch-index-default)))
;; Tags keybinding
(global-set-key (kbd "<f12>") 'xref-find-definitions)
@ -93,15 +90,15 @@
;; This is problematic if TAGS has changed
;; Clearing it here ensures the table won't get out of sync
(when tags-completion-table
(setq tags-completion-table nil))
(setq tags-completion-table nil))
(tags-completion-table)
(message "Refreshing ido tags list")
;; Reset to remove "empty" value as well as avoid duplicates
(setq macoy-tag-names nil)
(mapcar (lambda (x)
(push (prin1-to-string x t) macoy-tag-names))
tags-completion-table)
(push (prin1-to-string x t) macoy-tag-names))
tags-completion-table)
(message "Refreshing ido tags list done"))
(defun macoy-ido-find-tag ()
@ -125,7 +122,7 @@
(defvar ac-source-macoy-ido-tags
'(;;(init . macoy-ido-find-tag-refresh) ;; Commented because it runs every time (unnecessary)
(candidates . macoy-tag-names)
(candidates . macoy-tag-names)
(cache)))
;; Autocomplete from precompiled tags list (normal tags source is too slow)
@ -135,36 +132,38 @@
(setq-default ac-sources '(
ac-source-yasnippet
ac-source-words-in-same-mode-buffers
ac-source-macoy-ido-tags
ac-source-macoy-ido-tags
))
;; (setq ac-candidate-limit nil)
;; (setq ac-auto-show-menu nil)
;; Alternate find file in project thing using tags
;; If projectile isn't doing the trick, use tags instead
;; From https://www.emacswiki.org/emacs/InteractivelyDoThings#CompleteFindTagUsingIdo
(defun macoy-ido-find-file-in-tag-files ()
(interactive)
(save-excursion
(let ((enable-recursive-minibuffers t))
(visit-tags-table-buffer))
(find-file
(expand-file-name
(ido-completing-read
"Project file: " (tags-table-files) nil t)))))
(let ((enable-recursive-minibuffers t))
(visit-tags-table-buffer))
(find-file
(expand-file-name
(ido-completing-read
"Project file: " (tags-table-files) nil t)))))
;; Find references via tags-search. This is my find-references replacement
(defun macoy-tags-search ()
"Pick tag with `macoy-ido-find-tag' then run `tags-search' (or search marked)"
(interactive)
(if (use-region-p)
(tags-search (buffer-substring (region-beginning) (region-end)))
(tags-search (ido-completing-read "Tag: " macoy-tag-names))
))
(tags-search (buffer-substring (region-beginning) (region-end)))
(tags-search (ido-completing-read "Tag: " macoy-tag-names))))
;; Hippie Expand/DAbbrev settings
(setq hippie-expand-try-functions-list '(try-expand-dabbrev try-expand-dabbrev-all-buffers))
(global-set-key (kbd "M-SPC") 'set-mark-command)
(global-set-key (kbd "C-SPC") 'hippie-expand)
;; Find references
(global-set-key (kbd "C-\\") 'macoy-tags-search)
(global-set-key (kbd "C-|") 'tags-loop-continue)
@ -172,19 +171,16 @@
(defun macoy-tags-query-replace-marked (replacement)
(interactive (list
(read-string (format "Replace %s with: "
(buffer-substring (region-beginning) (region-end))))))
(read-string (format "Replace %s with: "
(buffer-substring (region-beginning) (region-end))))))
(tags-query-replace (buffer-substring (region-beginning) (region-end)) replacement)
)
(tags-query-replace (buffer-substring (region-beginning) (region-end)) replacement))
(defun macoy-tags-query-replace ()
(interactive)
(if (use-region-p)
(call-interactively 'macoy-tags-query-replace-marked (buffer-substring (region-beginning) (region-end)))
(call-interactively 'tags-query-replace)
)
)
(call-interactively 'macoy-tags-query-replace-marked (buffer-substring (region-beginning) (region-end)))
(call-interactively 'tags-query-replace)))
;;
;; Language Servers (the nuclear option)
@ -201,5 +197,5 @@
;; eglot language server alternative
;;(when (require 'eglot)
;; (add-to-list 'eglot-server-programs
;; '((c++ mode c-mode) . (eglot-cquery "f:/gitRepos/cquery/build/Release/cquery.exe")))
;; '((c++ mode c-mode) . (eglot-cquery "f:/gitRepos/cquery/build/Release/cquery.exe")))
;; )

44
Emacs/visual-early.el

@ -105,8 +105,12 @@
;; Show whitespace
(when (require 'whitespace)
;; Not enabled globally because it looks a bit too ugly for my tastes; I can toggle it when needed
;;(global-whitespace-mode 0)
(global-whitespace-mode 0)
(setq whitespace-style '(tab-mark space-mark))
;; (global-whitespace-mode 1)
;; (setq whitespace-style '(space-mark))
;; whitespace-trailing
;; whitespace-indentation
(set-face-foreground 'whitespace-indentation (face-background 'match))
@ -115,6 +119,14 @@
(setq whitespace-line-column 100)
(setq whitespace-newline nil)
;; (set-face-foreground 'whitespace-indentation (face-foreground 'font-lock-comment-face))
;; Doesn't work
;; (set-face-foreground 'whitespace-tab (face-foreground 'font-lock-comment-face))
;; Use | for tabs
;; (setq whitespace-display-mappings
;; '((tab-mark 9 [124 9] [92 9])))
;; Attempt at a global mode which only shows bad setups. Almost works, but Elisp isn't good
;; (setq macoy-whitespace-style-minimal '(face indentation trailing))
;; (setq macoy-whitespace-style-verbose '(tab-mark space-mark))
@ -124,20 +136,20 @@
;; (setq macoy-whitespace-verbose nil)
;; (defun macoy-toggle-whitespace-mode ()
;; (interactive)
;; ;; Toggle off and on to redraw buffer (could probably just call the function which does this...)
;; (whitespace-mode 0)
;; (setq macoy-whitespace-verbose (not macoy-whitespace-verbose))
;; (if macoy-whitespace-verbose
;; (setq whitespace-style macoy-whitespace-style-verbose)
;; (setq whitespace-style macoy-whitespace-style-minimal))
;; (whitespace-mode 1))
;; (interactive)
;; ;; Toggle off and on to redraw buffer (could probably just call the function which does this...)
;; (whitespace-mode 0)
;; (setq macoy-whitespace-verbose (not macoy-whitespace-verbose))
;; (if macoy-whitespace-verbose
;; (setq whitespace-style macoy-whitespace-style-verbose)
;; (setq whitespace-style macoy-whitespace-style-minimal))
;; (whitespace-mode 1))
(defun macoy-toggle-whitespace-mode ()
(interactive)
(if (bound-and-true-p whitespace-mode)
(whitespace-mode 0)
(whitespace-mode)))
(whitespace-mode 0)
(whitespace-mode)))
(global-set-key (kbd "S-<f9>") 'macoy-toggle-whitespace-mode))
;;
@ -146,8 +158,8 @@
(defun macoy-toggle-narrow ()
(interactive)
(if (buffer-narrowed-p)
(widen)
(narrow-to-defun)))
(widen)
(narrow-to-defun)))
(global-set-key (kbd "C-S-<f9>") 'macoy-toggle-narrow)
@ -170,9 +182,9 @@
(interactive)
(let ((default-directory macoy-auto-theme-script-dir))
(compile
(format "%s -format img::colors -in \"%s\" -out colors.txt && python3 AutoBase16Theme.py emacs-base16-theme-template.el %s"
macoy-auto-theme-schemer2-bin (read-file-name "Image: ") macoy-auto-theme-output-file))))
(compile
(format "%s -format img::colors -in \"%s\" -out colors.txt && python3 AutoBase16Theme.py emacs-base16-theme-template.el %s"
macoy-auto-theme-schemer2-bin (read-file-name "Image: ") macoy-auto-theme-output-file))))
;; Reference Windows command:
;;c:/Users/mmadson/go/bin/schemer2.exe -format img::colors -in C:/Users/mmadson/Downloads/Wallpapers/32\ -\ fHFDkjY.jpg -out colors.txt && python3 AutoBase16Theme.py emacs-base16-theme-template.el c:/Users/mmadson/AppData/Roaming/.emacs.d/elpa/base16-theme-20180320.2254/base16-my-auto-theme.el

Loading…
Cancel
Save