doom/repos/x-lib/x-lib.el

60 lines
1.7 KiB
EmacsLisp

;;; x-lib.el -*- lexical-binding: t -*-
;;
;;; Code:
(require 'subr-x)
;;;###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/kill-buffer ()
"Kill current buffer without prompting for which buffer."
(interactive)
(kill-buffer))
;;;###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)))
;;;###autoload
(defun +x/org-insert-link-with-title (url)
"Insert a link to URL with the title provided by the site itself."
(interactive "sURL for which to insert link: ")
(let ((title
(string-trim
(shell-command-to-string
(concat "curl -sL " url
" | "
"xmllint --html --xpath '//head/title/text()' - "
"2>/dev/null")))))
(insert "[[" url "][" title "]]")))
(provide 'x-lib)
;;; x-lib.el ends here