Move reusable function definitions to its x-lib

This commit is contained in:
Wojciech Kozlowski 2022-04-11 18:54:30 +02:00
parent f8ed569e92
commit fe3147aa33
3 changed files with 48 additions and 26 deletions

View File

@ -244,6 +244,10 @@
(define-key whole-line-or-region-local-mode-map [remap comment-dwim] nil) (define-key whole-line-or-region-local-mode-map [remap comment-dwim] nil)
(whole-line-or-region-global-mode +1)) (whole-line-or-region-global-mode +1))
;; Defer loading of local configuration library.
(use-package! x-lib
:defer t)
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; Global configuration. ;; Global configuration.
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
@ -285,33 +289,11 @@
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
(map! (map!
"C-M-\\" (defun +x/indent-region-or-buffer () "C-M-\\" #'+x/indent-region-or-buffer
"Indent a region if selected, otherwise the whole buffer."
(interactive)
(if (region-active-p)
(indent-region (region-beginning) (region-end))
(indent-region (point-min) (point-max))))
"C-x k" #'kill-current-buffer "C-x k" #'kill-current-buffer
"C-<" #'+x/scroll-down-one
"C-<" (defun +x/scroll-down-one () "C->" #'+x/scroll-up-one
"Scroll text (but not the point) of selected window downward one line." "M-Q" #'+x/unfill-paragraph
(interactive)
(let ((scroll-preserve-screen-position nil)) (scroll-down 1)))
"C->" (defun +x/scroll-up-one ()
"Scroll text (but not the point) of selected window upward one line."
(interactive)
(let ((scroll-preserve-screen-position nil)) (scroll-up 1)))
"M-Q" (defun +x/unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
;; This would override `fill-column' if it's an integer.
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
;; Create binding before dired is loaded. ;; Create binding before dired is loaded.
"C-x C-j" #'dired-jump "C-x C-j" #'dired-jump
;; More convenient window switching. ;; More convenient window switching.

View File

@ -14,6 +14,8 @@
(package! duplicate-thing) (package! duplicate-thing)
(package! treemacs-icons-dired) (package! treemacs-icons-dired)
(package! whole-line-or-region) (package! whole-line-or-region)
(package! x-lib
:recipe (:local-repo "repos/x-lib"))
;; To install a package directly from a remote git repo, you must specify a ;; To install a package directly from a remote git repo, you must specify a
;; `:recipe'. You'll find documentation on what `:recipe' accepts here: ;; `:recipe'. You'll find documentation on what `:recipe' accepts here:

38
repos/x-lib/x-lib.el Normal file
View File

@ -0,0 +1,38 @@
;;; x-lib.el -*- lexical-binding: t -*-
;;
;;; Code:
;;;###autoload
(defun +x/indent-region-or-buffer ()
"Indent a region if selected, otherwise the whole buffer."
(interactive)
(if (region-active-p)
(indent-region (region-beginning) (region-end))
(indent-region (point-min) (point-max))))
;;;###autoload
(defun +x/scroll-down-one ()
"Scroll text (but not the point) of selected window downward one line."
(interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-down 1)))
;;;###autoload
(defun +x/scroll-up-one ()
"Scroll text (but not the point) of selected window upward one line."
(interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-up 1)))
;;;###autoload
(defun +x/unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
;; This would override `fill-column' if it's an integer.
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
(provide 'x-lib)
;;; x-lib.el ends here