emacs/lisp/mitch-defuns.el

180 lines
6.8 KiB
EmacsLisp
Raw Normal View History

2022-06-19 14:13:36 -08:00
;;; mitch-defuns.el --- custom-defined functions
;;; Commentary:
;; _ _ _
;; _ __ ___ (_)| |_ ___ | |__
;; | '_ ` _ \ | || __|/ __|| '_ \ _____
;; | | | | | || || |_| (__ | | | ||_____|
;; |_| |_| |_||_| \__|\___||_| |_|
;; _ __ _
;; __| | ___ / _| _ _ _ __ ___ ___ | |
;; / _` | / _ \| |_ | | | || '_ \ / __| / _ \| |
;; | (_| || __/| _|| |_| || | | |\__ \ _ | __/| |
;; \__,_| \___||_| \__,_||_| |_||___/(_) \___||_|
;;
;; Some functions to run when loading packages...
;;; Code:
(defun mitch/evil-config ()
"A batch of commands to run as the :config of evil's `use-package'.
Made solely to reduce lines in the init-file."
;; Visual moving
(defun move-screen-down-line ()
"Scroll down line but keep cursor in same visual position."
(interactive)
(evil-previous-line)
(scroll-down-line))
(defun move-screen-up-line ()
"Scroll up line but keep cursor in same visual position."
(interactive)
(evil-next-line)
(scroll-up-line))
2022-10-26 09:44:13 -08:00
;; Make evil-join combine lines. Taken from https://github.com/doomemacs/doomemacs/blob/master/modules/editor/evil/autoload/advice.el#L180
;;;###autoload (autoload '+evil-join-a "lisp/mitch-defuns" nil nil)
;; (defun +evil-join-a (fn beg end)
;; "Join the selected lines.
;; This advice improves on `evil-join' by removing comment delimiters when joining
;; commented lines, without `fill-region-as-paragraph'.
;; Adapted from https://github.com/emacs-evil/evil/issues/606"
;; (if-let* (((not (= (line-end-position) (point-max))))
;; (cend (save-excursion (goto-char end) (line-end-position)))
;; (cbeg (save-excursion
;; (goto-char beg)
;; (and (doom-point-in-comment-p
;; (save-excursion
;; (goto-char (line-beginning-position 2))
;; (skip-syntax-forward " \t")
;; (point)))
;; (or (comment-search-backward (line-beginning-position) t)
;; (comment-search-forward (line-end-position) t)
;; (and (doom-point-in-comment-p beg)
;; (stringp comment-continue)
;; (or (search-forward comment-continue (line-end-position) t)
;; beg)))))))
;; (let* ((count (count-lines beg end))
;; (count (if (> count 1) (1- count) count))
;; (fixup-mark (make-marker)))
;; (uncomment-region (line-beginning-position 2)
;; (save-excursion
;; (goto-char cend)
;; (line-end-position 0)))
;; (unwind-protect
;; (dotimes (_ count)
;; (join-line 1)
;; (save-match-data
;; (when (or (and comment-continue
;; (not (string-empty-p comment-continue))
;; (looking-at (concat "\\(\\s-*" (regexp-quote comment-continue) "\\) ")))
;; (and comment-start-skip
;; (not (string-empty-p comment-start-skip))
;; (looking-at (concat "\\(\\s-*" comment-start-skip "\\)"))))
;; (replace-match "" t nil nil 1)
;; (just-one-space))))
;; (set-marker fixup-mark nil)))
;; ;; But revert to the default we're not in a comment, where
;; ;; `fill-region-as-paragraph' is too greedy.
;; (funcall fn beg end)))
;; (advice-add #'evil-join :override #'+evil-join-a)
2022-06-19 14:13:36 -08:00
)
(defun mitch/visual-setup ()
"Commands to run when setting up any display. To be called in use-package
declarations for color schemes."
(tooltip-mode -1)
(menu-bar-mode -1)
(set-face-attribute 'fixed-pitch nil
:family "MesloLGS NF")
(set-face-attribute 'default nil
:family "MesloLGS NF")
(set-face-attribute 'variable-pitch nil
:inherit 'default
:family "Sans Serif")
(setq window-divider-default-places t)
(setq right-divider-width 5)
(setq ring-bell-function 'ignore)
(setq rainbow-delimiters-max-face-count 2)
(add-to-list 'initial-frame-alist '(alpha-background . 50))
(add-to-list 'default-frame-alist '(alpha-background . 50))
(add-to-list 'default-frame-alist '(cursor-color . "white"))
(add-to-list 'default-frame-alist '(fullscreen . maximized))
;; see also https://emacs.stackexchange.com/questions/7228/nice-tty-window-borders-in-24-4
(let ((display-table (or standard-display-table (make-display-table))))
(set-display-table-slot display-table 'vertical-border (make-glyph-code ?│))
(setq standard-display-table display-table)))
2022-06-19 14:13:36 -08:00
(defun mitch/graphical-setup ()
"Commands to run at the beginning of init when on a graphical display.
This prevents errors in termux and speeds up init when editing from the
console."
2022-06-19 14:13:36 -08:00
;; hide gui scrollbars and menubar etc
(scroll-bar-mode -1) ;; use `yascroll' instead
2022-06-19 14:13:36 -08:00
(setq scroll-bar-adjust-thumb-portion nil)
(tool-bar-mode 0)
(menu-bar-mode 0)
(set-fringe-mode 8)
;; diable stupid file open box thingy
(setq use-file-dialog nil)
(setq use-dialog-box nil)
;; Pixel scrolling. Only in emacs 29+...
(if (>= (string-to-number emacs-version) 29)
(pixel-scroll-precision-mode t)
(pixel-scroll-mode t))
;; Size of text. お前 わ 毛 しんでる.
(if (eq system-type 'gnu/linux)
(progn
(set-face-attribute 'fixed-pitch nil :height 130)
(set-face-attribute 'default nil :height 130)
(set-face-attribute 'variable-pitch nil :height 140))
(progn
(set-face-attribute 'fixed-pitch nil :height 100)
(set-face-attribute 'default nil :height 100)
(set-face-attribute 'variable-pitch nil :height 110))))
2022-06-19 14:13:36 -08:00
(defun toggle-ja-input ()
"Switch between english and japanese. Broken."
(interactive)
(if (eq current-input-method 'japanese)
(setq current-input-method 'japanese-ascii)
(setq current-input-method 'japanese)))
(defun mitch/general-config ()
"A batch of commands to run immediately after loading the `general' package.
Made solely to reduce lines in the init file."
(require 'mitch-keybinds))
(defun turn-off-line-numbers ()
"A tiny wrapper around `display-line-numbers-mode' or `linum'.
2022-06-19 14:13:36 -08:00
For use in hooks."
(interactive)
(if (bound-and-true-p display-line-numbers-mode)
(display-line-numbers-mode -1))
2022-07-22 16:23:10 -08:00
(if (fboundp #'linum-mode)
(linum-mode -1))
(if (fboundp #'linum-relative-mode)
(linum-relative-mode -1)))
2022-06-19 14:13:36 -08:00
(defun mitch/terminal-setup ()
"A batch of commands to run when opening anything that looks like a terminal.
For instance:
- Shell
- (ansi-)term
- eshell
- vterm
- Maybe SLIME too."
(turn-off-line-numbers))
;; for vterm
(defun update-pwd (path)
"Sync Emacs' working PATH with the shell's.
For use with `vterm'."
(setq default-directory path))
2022-08-11 06:25:28 -08:00
;; reference: https://stackoverflow.com/questions/4114577/how-do-i-define-an-emacs-lisp-function-to-spawn-a-shell-buffer-with-a-particular
(defun spawn-shell (name)
"Invoke shell test"
(interactive "MName of shell buffer to create: ")
(pop-to-buffer (get-buffer-create (generate-new-buffer-name name)))
(shell (current-buffer)))
2022-06-19 14:13:36 -08:00
;; This one line cost me over an hour of frustration...
(provide 'mitch-defuns)
;;; mitch-defuns.el ends here