.emacs.d/custom.el

89 lines
2.8 KiB
EmacsLisp
Raw Normal View History

2021-05-16 15:40:41 +00:00
;;; Compilation
2020-12-20 21:07:30 +00:00
(setq compile-command "make ")
2021-05-16 15:40:41 +00:00
;; C-m functions as \r, so pressing C-x C-m C-m will call compile and skip the prompt.
2021-02-23 11:46:16 +00:00
(global-set-key (kbd "C-x C-m") 'compile)
2021-05-16 15:40:41 +00:00
;; Nicer movement in compilation-mode.
(add-hook 'compilation-mode-hook
(lambda () (local-set-key (kbd "n") 'compilation-next-error)))
(add-hook 'compilation-mode-hook
(lambda () (local-set-key (kbd "p") 'compilation-previous-error)))
2021-05-16 15:40:41 +00:00
;; Function for selecting the current line.
(defun fez/mark-line ()
"Selects the current line with the mark."
2021-02-23 11:46:16 +00:00
(interactive)
(move-beginning-of-line nil)
(set-mark (point))
(move-end-of-line nil))
2021-05-16 15:40:41 +00:00
;; Toggle between indenting with tabs or spaces.
(defun fez/toggle-indent ()
2021-03-17 11:51:55 +00:00
(interactive)
(setq-default indent-tabs-mode (not indent-tabs-mode)))
2021-04-09 15:56:51 +00:00
2021-05-16 15:40:41 +00:00
(defun fez/current-line-empty-p ()
(save-excursion
(beginning-of-line)
(looking-at-p "[[:space:]]*$")))
2021-05-16 15:40:41 +00:00
(defun fez/flash-region (&optional timeout)
"Temporarily highlight region from START to END. Taken from SLIME source code and modified."
(interactive)
(transient-mark-mode)
(save-excursion
(mark-defun)
2021-05-16 15:40:41 +00:00
;; Don't mark the line above the s-expression.
(while (fez/current-line-empty-p)
(forward-char))
(let* ((start (region-beginning))
(end (region-end))
(overlay (make-overlay start end)))
(deactivate-mark)
(overlay-put overlay 'face 'secondary-selection)
(run-with-timer (or timeout 0.2) nil 'delete-overlay overlay)))
(transient-mark-mode))
2021-05-16 15:40:41 +00:00
2021-05-21 09:11:17 +00:00
(defun fez/insert-keybind ()
(interactive)
(insert (concat "(kbd \""
(key-description (read-key-sequence-vector "Key sequence: "))
"\")")))
2021-05-26 12:20:59 +00:00
(defun fez/time-stamp ()
(interactive)
(shell-command "LANG=nb_NO.UTF-8 date +%d-%m-%Y" t))
2021-05-16 15:40:41 +00:00
;; Eshell convinience commands.
(defalias 'open 'find-file-other-window)
(defalias 'clean 'eshell/clear-scrollback)
;;; Keybinds
;; C-x C-z and C-z are normally mapped to suspend-frame, an absolutely useless function.
;; Unbind them before making the keybind useful.
(global-unset-key (kbd "C-x C-z"))
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-x C-z") 'fez/mark-line)
;; Better buffer management (smol).
(global-set-key (kbd "C-x C-b") 'bs-show)
;; Insipiration from Nyxt, kill the current buffer.
(global-set-key (kbd "C-x C-k") 'kill-this-buffer)
2021-05-26 12:20:59 +00:00
(global-set-key (kbd "C-c t") 'fez/time-stamp)
2021-05-16 15:40:41 +00:00
;; Binds for switching between light and dark themes.
(global-set-key [f5] (lambda ()
(interactive)
(disable-theme 'basic)
(load-theme 'magik)))
(global-set-key [f6] (lambda ()
(interactive)
(disable-theme 'magik)
(load-theme 'basic)))
2021-05-21 09:18:49 +00:00
(add-hook 'emacs-lisp-mode-hook
(lambda () (local-set-key (kbd "C-c k") #'fez/insert-keybind)))