.emacs.d/emacs/rc.el

164 lines
5.3 KiB
EmacsLisp

(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(column-number-mode 1)
(show-paren-mode 1)
(electric-pair-mode 1)
;; (add-hook 'dired-mode-hook 'dired-hide-details-mode)
(add-hook 'dired-mode-hook 'dired-omit-mode)
(setq dired-omit-extensions nil)
(setq dired-omit-files (rx (seq bol ".")))
(display-line-numbers-mode -1)
(setq-default display-line-numbers nil)
(dolist (hook '(prog-mode-hook
yaml-mode-hook
git-commit-setup-hook))
(add-hook hook (lambda () (setq-local display-line-numbers 'relative))))
(setq global-hl-line-mode -1)
(defun +magit-display-buffer (buffer)
(display-buffer
buffer (if (derived-mode-p 'magit-mode)
'(display-buffer-same-window)
'(nil (inhibit-same-window . t)))))
;; (defun +duplicate-line ()
;; "Duplicate current line"
;; (interactive)
;; (let ((column (- (point) (point-at-bol)))
;; (line (let ((s (thing-at-point 'line t)))
;; (if s (string-remove-suffix "\n" s) ""))))
;; (move-end-of-line 1)
;; (newline)
;; (insert line)
;; (move-beginning-of-line 1)
;; (forward-char column)))
(defun +enlarge-window-horizontally ()
(interactive)
(enlarge-window-horizontally 5))
(defun +enlarge-window ()
(interactive)
(enlarge-window 5))
(defun +shrink-window-horizontally ()
(interactive)
(shrink-window-horizontally 5))
(defun +shrink-window ()
(interactive)
(shrink-window 5))
(defun +delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times.
This command does not push text to `kill-ring'."
(interactive "p")
(delete-region
(point)
(progn
(forward-word arg)
(point))))
;; (add-hook 'emacs-startup-hook (lambda ()
;; (when (get-buffer "*scratch*")
;; (kill-buffer "*scratch*"))))
;;; Whitespace mode
(defun +set-up-whitespace-handling ()
(interactive)
(whitespace-mode 1)
(add-to-list 'write-file-functions 'delete-trailing-whitespace))
(dolist (hook '(prog-mode-hook
yaml-mode-hook
git-commit-setup-hook))
(add-hook hook #'+set-up-whitespace-handling))
(defun +backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument, do this that many times.
This command does not push text to `kill-ring'."
(interactive "p")
(+delete-word (- arg)))
;; (dolist (hook '(dired-mode-hook
;; vterm-mode-hook
;; ibuffer-mode-hook
;; scratch-buffer-hook))
;; (add-hook hook (lambda () (solaire-mode -1))))
;; (eval-after-load "simple"
;; `(defun get-scratch-buffer-create ()
;; "Return the *scratch* buffer, creating a new one if needed."
;; (run-hooks 'scratch-buffer-hook)
;; (or (get-buffer "*scratch*")
;; (let ((scratch (get-buffer-create "*scratch*")))
;; ;; Don't touch the buffer contents or mode unless we know that
;; ;; we just created it.
;; (with-current-buffer scratch
;; (when initial-scratch-message
;; (insert (substitute-command-keys initial-scratch-message))
;; (set-buffer-modified-p nil))
;; (funcall initial-major-mode))
;; scratch))))
(global-set-key (kbd "C-j")
(defun +join-next-line ()
(interactive)
(join-line -1)))
(defun temp-buffer-p (window new-buffer bury-or-kill)
(when (string-match-p "^\*.+\*$" (buffer-name new-buffer))
return t))
(setq switch-to-prev-buffer-skip 'temp-buffer-p)
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
(global-set-key (kbd "C-x C-\\") 'toggle-window-split)
(global-set-key (kbd "C-c f r") 'recentf-open)
(global-set-key (kbd "C-c f f") 'find-file)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-x }") '+enlarge-window-horizontally)
(global-set-key (kbd "C-x {") '+shrink-window-horizontally)
(global-set-key (kbd "C-c ^") '+enlarge-window)
(global-set-key (kbd "C-c 0") 'balance-windows)
(global-set-key (kbd "M-n") 'next-buffer)
(global-set-key (kbd "M-p") 'previous-buffer)
(global-set-key (kbd "<C-backspace>") '+backward-delete-word)
(global-set-key (kbd "<C-delete>") '+delete-word)
(global-unset-key (kbd "C-x C-f"))
(global-unset-key (kbd "C-x C-b"))
(set-input-method 'russian-computer)
(deactivate-input-method)