theurgy/navigation.el
2025-08-17 23:40:44 +08:00

88 lines
2.9 KiB
EmacsLisp

;;; navigation.el --- Navigation behavior config -*- lexical-binding: t -*-
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; commentary
;;; Code:
;; Smooth scrolling
(setq bidi-paragraph-direction 'left-to-right
bidi-inhibit-bpa t
bidi-display-reordering nil)
(use-package ultra-scroll
:straight (:host github
:repo "jdtsmith/ultra-scroll")
:init
(setq scroll-conservatively 3 ; or whatever value you prefer, since v0.4
scroll-margin 0) ; important: scroll-margin>0 not yet supported
:config
(ultra-scroll-mode 1))
;; Keyboard Scrolling
(global-set-key (kbd "C-<down>") '(lambda () (interactive) (scroll-up-line)))
(global-set-key (kbd "C-<up>") '(lambda () (interactive) (scroll-down-line)))
(global-set-key (kbd "C-S-<down>") '(lambda () (interactive) (scroll-up-line 10)))
(global-set-key (kbd "C-S-<up>") '(lambda () (interactive) (scroll-down-line 10)))
(global-set-key (kbd "M-<up>") #'scroll-other-window-down)
(global-set-key (kbd "M-<down>") #'scroll-other-window)
;; Windmove bindings
(global-set-key (kbd "C-c <left>") 'windmove-left)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <up>") 'windmove-up)
(global-set-key (kbd "C-c <down>") 'windmove-down)
;; Fullscreen and maximize button
(global-set-key (kbd "C-x <f10>") 'toggle-frame-maximized)
(global-set-key (kbd "C-x <f11>") 'toggle-frame-fullscreen)
;; Line jumps
(defun jump-to-line-absolute ()
(interactive)
(let ((p display-line-numbers))
(setq display-line-numbers t)
(call-interactively 'goto-line)
(setq display-line-numbers p)))
(defun relative-line-jump-helper (relative-line)
(interactive "nGoto line: ")
(goto-line (+ (line-number-at-pos) relative-line) '() t))
(defun jump-to-line-relative ()
(interactive)
(let ((p display-line-numbers))
(setq display-line-numbers 'relative)
(call-interactively 'relative-line-jump-helper)
(setq display-line-numbers p)))
(global-set-key (kbd "M-g g") 'jump-to-line-absolute)
(global-set-key (kbd "M-g r") 'jump-to-line-relative)
;; Eglot and flymake bindings
(global-set-key (kbd "M-g <left>") 'flymake-goto-prev-error)
(global-set-key (kbd "M-g <right>") 'flymake-goto-next-error)
(global-set-key (kbd "C-x M-f") 'eglot-code-actions)
(provide 'navigation)
;;; navigation.el ends here