2017-06-08 11:47:56 +02:00
|
|
|
|
;;; core/autoload/ui.el -*- lexical-binding: t; -*-
|
2017-02-01 00:31:58 -05:00
|
|
|
|
|
2018-09-07 19:38:16 -04:00
|
|
|
|
;;
|
|
|
|
|
;; Public library
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom-resize-window (window new-size &optional horizontal force-p)
|
|
|
|
|
"Resize a window to NEW-SIZE. If HORIZONTAL, do it width-wise.
|
|
|
|
|
If FORCE-P is omitted when `window-size-fixed' is non-nil, resizing will fail."
|
|
|
|
|
(with-selected-window (or window (selected-window))
|
|
|
|
|
(let ((window-size-fixed (unless force-p window-size-fixed)))
|
|
|
|
|
(enlarge-window (- new-size (if horizontal (window-width) (window-height)))
|
|
|
|
|
horizontal))))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom-quit-p (&optional prompt)
|
|
|
|
|
"Prompt the user for confirmation when killing Emacs.
|
|
|
|
|
|
|
|
|
|
Returns t if it is safe to kill this session. Does not prompt if no real buffers
|
|
|
|
|
are open."
|
|
|
|
|
(or (not (ignore-errors (doom-real-buffer-list)))
|
|
|
|
|
(yes-or-no-p (format "››› %s" (or prompt "Quit Emacs?")))
|
|
|
|
|
(ignore (message "Aborted"))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;; Advice
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom*recenter (&rest _)
|
|
|
|
|
"Generic advisor for recentering window (typically :after other functions)."
|
|
|
|
|
(recenter))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom*shut-up (orig-fn &rest args)
|
|
|
|
|
"Generic advisor for silencing noisy functions."
|
|
|
|
|
(quiet! (apply orig-fn args)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;; Hooks
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom|apply-ansi-color-to-compilation-buffer ()
|
|
|
|
|
"Applies ansi codes to the compilation buffers. Meant for
|
|
|
|
|
`compilation-filter-hook'."
|
|
|
|
|
(with-silent-modifications
|
|
|
|
|
(ansi-color-apply-on-region compilation-filter-start (point))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;; Commands
|
|
|
|
|
|
2017-02-01 00:31:58 -05:00
|
|
|
|
;;;###autoload
|
2018-01-30 01:10:16 -05:00
|
|
|
|
(defun doom/toggle-line-numbers ()
|
|
|
|
|
"Toggle line numbers.
|
|
|
|
|
|
|
|
|
|
Cycles through regular, relative and no line numbers. The order depends on what
|
2018-08-29 01:11:50 +02:00
|
|
|
|
`display-line-numbers-type' is set to. If you're using Emacs 26+, and
|
|
|
|
|
visual-line-mode is on, this skips relative and uses visual instead.
|
2018-01-30 01:10:16 -05:00
|
|
|
|
|
2018-08-29 01:11:50 +02:00
|
|
|
|
See `display-line-numbers' for what these values mean."
|
2018-01-30 01:10:16 -05:00
|
|
|
|
(interactive)
|
2018-08-29 01:11:50 +02:00
|
|
|
|
(defvar doom--line-number-style display-line-numbers-type)
|
2018-09-07 20:08:06 -04:00
|
|
|
|
(let* ((styles `(t ,(if (and EMACS26+ visual-line-mode) 'visual 'relative) nil))
|
|
|
|
|
(order (cons display-line-numbers-type (remq display-line-numbers-type styles)))
|
|
|
|
|
(queue (memq doom--line-number-style order))
|
|
|
|
|
(next (if (= (length queue) 1)
|
|
|
|
|
(car order)
|
|
|
|
|
(car (cdr queue)))))
|
|
|
|
|
(setq doom--line-number-style next)
|
|
|
|
|
(if EMACS26+
|
|
|
|
|
(setq display-line-numbers next)
|
|
|
|
|
(pcase next
|
|
|
|
|
(`t (nlinum-relative-off) (nlinum-mode +1))
|
|
|
|
|
(`relative (nlinum-relative-on))
|
|
|
|
|
(`nil (nlinum-mode -1))))
|
|
|
|
|
(message "Switched to %s line numbers"
|
|
|
|
|
(pcase next
|
|
|
|
|
(`t "normal")
|
|
|
|
|
(`nil "disabled")
|
|
|
|
|
(_ (symbol-name next))))))
|
2017-02-01 00:31:58 -05:00
|
|
|
|
|
2018-09-07 19:38:16 -04:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom/delete-frame ()
|
|
|
|
|
"Delete the current frame, but ask for confirmation if it isn't empty."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if (cdr (frame-list))
|
|
|
|
|
(when (doom-quit-p "Close frame?")
|
|
|
|
|
(delete-frame))
|
|
|
|
|
(save-buffers-kill-emacs)))
|
2017-05-19 03:00:27 +02:00
|
|
|
|
|
2017-02-19 18:11:44 -05:00
|
|
|
|
;;;###autoload
|
2019-03-12 17:50:45 +00:00
|
|
|
|
(defun doom/window-maximize-buffer ()
|
2017-12-08 22:15:26 -05:00
|
|
|
|
"Close other windows to focus on this one. Activate again to undo this. If the
|
|
|
|
|
window changes before then, the undo expires.
|
|
|
|
|
|
|
|
|
|
Alternatively, use `doom/window-enlargen'."
|
2017-02-19 18:11:44 -05:00
|
|
|
|
(interactive)
|
2017-05-11 09:48:12 +02:00
|
|
|
|
(if (and (one-window-p)
|
2018-09-28 20:48:41 -04:00
|
|
|
|
(assq ?_ register-alist))
|
2017-05-11 09:48:12 +02:00
|
|
|
|
(jump-to-register ?_)
|
|
|
|
|
(window-configuration-to-register ?_)
|
|
|
|
|
(delete-other-windows)))
|
2017-05-19 03:00:27 +02:00
|
|
|
|
|
2017-05-19 15:56:35 +02:00
|
|
|
|
(defvar doom--window-enlargened nil)
|
2017-05-19 03:00:27 +02:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom/window-enlargen ()
|
2017-12-08 22:15:26 -05:00
|
|
|
|
"Enlargen the current window to focus on this one. Does not close other
|
2019-03-12 17:50:45 +00:00
|
|
|
|
windows (unlike `doom/window-maximize-buffer') Activate again to undo."
|
2017-05-19 03:00:27 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq doom--window-enlargened
|
|
|
|
|
(if (and doom--window-enlargened
|
2018-09-28 20:48:41 -04:00
|
|
|
|
(assq ?_ register-alist))
|
2018-08-27 20:02:16 +02:00
|
|
|
|
(ignore (ignore-errors (jump-to-register ?_)))
|
2017-05-19 03:00:27 +02:00
|
|
|
|
(window-configuration-to-register ?_)
|
2018-08-23 17:21:28 +02:00
|
|
|
|
(if (window-dedicated-p)
|
|
|
|
|
;; `window-resize' and `window-max-delta' don't respect
|
|
|
|
|
;; `ignore-window-parameters', so we gotta force it to.
|
|
|
|
|
(cl-letf* ((old-window-resize (symbol-function #'window-resize))
|
|
|
|
|
(old-window-max-delta (symbol-function #'window-max-delta))
|
|
|
|
|
((symbol-function #'window-resize)
|
|
|
|
|
(lambda (window delta &optional horizontal _ignore pixelwise)
|
|
|
|
|
(funcall old-window-resize window delta horizontal
|
|
|
|
|
t pixelwise)))
|
|
|
|
|
((symbol-function #'window-max-delta)
|
|
|
|
|
(lambda (&optional window horizontal _ignore trail noup nodown pixelwise)
|
|
|
|
|
(funcall old-window-max-delta window horizontal t
|
|
|
|
|
trail noup nodown pixelwise))))
|
|
|
|
|
(maximize-window))
|
|
|
|
|
(maximize-window))
|
2017-05-19 03:00:27 +02:00
|
|
|
|
t)))
|
2017-06-11 14:05:14 +02:00
|
|
|
|
|
2019-03-12 17:50:45 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom/window-maximize-horizontally ()
|
|
|
|
|
"Delete all windows to the left and right of the current window."
|
|
|
|
|
(interactive)
|
|
|
|
|
(require 'windmove)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (ignore-errors (windmove-left)) (delete-window))
|
|
|
|
|
(while (ignore-errors (windmove-right)) (delete-window))))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom/window-maximize-vertically ()
|
|
|
|
|
"Delete all windows above and below the current window."
|
|
|
|
|
(interactive)
|
|
|
|
|
(require 'windmove)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(while (ignore-errors (windmove-up)) (delete-window))
|
|
|
|
|
(while (ignore-errors (windmove-down)) (delete-window))))
|
|
|
|
|
|
2018-09-13 11:09:48 -04:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom/set-frame-opacity (opacity)
|
|
|
|
|
"Interactively change the current frame's opacity.
|
|
|
|
|
|
|
|
|
|
OPACITY is an integer between 0 to 100, inclusive."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (read-number "Opacity (0-100): "
|
|
|
|
|
(or (frame-parameter nil 'alpha)
|
|
|
|
|
100))))
|
|
|
|
|
(set-frame-parameter nil 'alpha opacity))
|
|
|
|
|
|
2019-03-02 01:12:48 -05:00
|
|
|
|
(defvar-local doom--buffer-narrowed-origin nil)
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun doom/clone-and-narrow-buffer (beg end &optional clone-p)
|
|
|
|
|
"Restrict editing in this buffer to the current region, indirectly. With CLONE-P,
|
|
|
|
|
clone the buffer and hard-narrow the selection. If mark isn't active, then widen
|
|
|
|
|
the buffer (if narrowed).
|
|
|
|
|
|
|
|
|
|
Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
|
|
|
|
(interactive "rP")
|
|
|
|
|
(cond ((or (region-active-p)
|
|
|
|
|
(and beg end))
|
|
|
|
|
(deactivate-mark)
|
|
|
|
|
(when clone-p
|
|
|
|
|
(let ((old-buf (current-buffer)))
|
|
|
|
|
(switch-to-buffer (clone-indirect-buffer nil nil))
|
|
|
|
|
(setq doom--buffer-narrowed-origin old-buf)))
|
|
|
|
|
(narrow-to-region beg end))
|
|
|
|
|
(doom--buffer-narrowed-origin
|
|
|
|
|
(kill-this-buffer)
|
|
|
|
|
(switch-to-buffer doom--buffer-narrowed-origin)
|
|
|
|
|
(setq doom--buffer-narrowed-origin nil))
|
|
|
|
|
(t
|
|
|
|
|
(widen))))
|
|
|
|
|
|
2018-09-07 19:38:16 -04:00
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;; Modes
|
2017-06-28 16:18:22 +02:00
|
|
|
|
|
2017-07-04 19:52:21 +02:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(define-minor-mode doom-big-font-mode
|
|
|
|
|
"A global mode that resizes the font, for streams, screen-sharing and
|
2018-09-28 20:48:19 -04:00
|
|
|
|
presentations.
|
|
|
|
|
|
|
|
|
|
Uses `doom-big-font' when enabled."
|
2017-07-04 19:52:21 +02:00
|
|
|
|
:init-value nil
|
|
|
|
|
:lighter " BIG"
|
|
|
|
|
:global t
|
2018-09-28 20:48:19 -04:00
|
|
|
|
(unless doom-big-font
|
|
|
|
|
(user-error "`doom-big-font' must be set to a valid font"))
|
|
|
|
|
(unless doom-font
|
|
|
|
|
(user-error "`doom-font' must be set to a valid font"))
|
2019-01-21 22:13:39 -05:00
|
|
|
|
(let ((doom-font (if doom-big-font-mode
|
|
|
|
|
doom-big-font
|
|
|
|
|
doom-font)))
|
|
|
|
|
(setf (alist-get 'font default-frame-alist)
|
|
|
|
|
(cond ((null doom-font))
|
|
|
|
|
((stringp doom-font) doom-font)
|
|
|
|
|
((fontp doom-font) (font-xlfd-name doom-font))
|
|
|
|
|
((signal 'wrong-type-argument (list '(fontp stringp) doom-font)))))
|
|
|
|
|
(set-frame-font doom-font t t)))
|