diff --git a/configuration.org b/configuration.org index 1611c10..ceb9276 100644 --- a/configuration.org +++ b/configuration.org @@ -2,77 +2,6 @@ This is a collection of functions and commands i wrote or stole from all around the internet. -** Navigation - -*** Move to different beginnings/ends of the current line - -Inspired by Bozhidar Batsov's [[http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/][solution]]. - -#+begin_src emacs-lisp -(defun gpolonkai/move-to-beginning-of-line () - "Move to different beginnings of the line. - -These are, in order: - -- beginning of the visual line if `visual-line-mode' is active, -- the first non-whitespace (indentation), -- the actual beginning of the line. - -This function will jump between the first character and the -indentation if used multiple times." - (interactive) - (let ((last-pos (point))) - (when visual-line-mode - (beginning-of-visual-line)) - (when (= (point) last-pos) - (back-to-indentation)) - (when (= (point) last-pos) - (beginning-of-line)) - (when (and (eq major-mode 'org-mode) - (= (point) last-pos)) - (org-beginning-of-line)) - (when (= (point) last-pos) - (back-to-indentation)))) - -(defun gpolonkai/move-to-end-of-line () - "Move to the end of the line. - -If `visual-line-mode' is active, jump to the end of the visual -line first. Then jump to the actual end of the line." - (interactive) - (let ((last-pos (point))) - (when visual-line-mode - (end-of-visual-line)) - (when (= (point) last-pos) - (end-of-line)) - (when (and (eq major-mode 'org-mode) - (= (point) last-pos)) - (org-end-of-line)))) -#+end_src - -*** Move to the next occurence of a character within the same line - -#+begin_src emacs-lisp -(defun gpolonkai/goto-next-char (chr) - (interactive "c") - (when (search-forward (char-to-string chr) (pos-eol) t) - (backward-char))) -#+end_src - -*** Move to the beginning of the next word - -#+begin_src emacs-lisp -(defun gpolonkai/beginning-of-next-word () - (interactive) - (let ((current-point (point))) - (forward-word 1) - (backward-word 1) - - (when (<= (point) current-point) - (forward-word 2) - (backward-word 1)))) -#+end_src - ** File manipulation *** Rename the current file diff --git a/init.el b/init.el index dbe3c6b..db6e6e8 100644 --- a/init.el +++ b/init.el @@ -61,6 +61,7 @@ (load "gpolonkai/windows") (load "gpolonkai/org-utils") (load "gpolonkai/text-utils") +(load "gpolonkai/nav-utils") ;; I started moving my configuration to this Org file. It’s easier to document this way. (org-babel-load-file (expand-file-name "configuration.org" user-emacs-directory)) diff --git a/lisp/gpolonkai/nav-utils.el b/lisp/gpolonkai/nav-utils.el new file mode 100644 index 0000000..eb16b1a --- /dev/null +++ b/lisp/gpolonkai/nav-utils.el @@ -0,0 +1,88 @@ +;;; gpolonkai/nav-utils.el --- Navigation utilities +;;; +;;; SPDX-License-Identifier: GPL-3.0-or-later +;;; Copyright © 2025 Gergely Polonkai +;;; This library is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU Lesser General Public +;;; License as published by the Free Software Foundation; either +;;; version 3 of the License, or (at your option) any later version. +;;; +;;; This library 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 +;;; Lesser General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with this library; if not, write to the +;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;;; Boston, MA 02111-1307, USA. +;;; +;;; Commentary: +;;; +;;; Utility functions stolen from the Internet or written by me +;;; +;;; Code: + +;; Inspired by Bozhidar Batsov's solution: +;; http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/ + +(defun gpolonkai/move-to-beginning-of-line () + "Move to different beginnings of the line. + +These are, in order: + +- beginning of the visual line if `visual-line-mode' is active, +- the first non-whitespace (indentation), +- the actual beginning of the line. + +This function will jump between the first character and the +indentation if used multiple times." + (interactive) + (let ((last-pos (point))) + (when visual-line-mode + (beginning-of-visual-line)) + (when (= (point) last-pos) + (back-to-indentation)) + (when (= (point) last-pos) + (beginning-of-line)) + (when (and (eq major-mode 'org-mode) + (= (point) last-pos)) + (org-beginning-of-line)) + (when (= (point) last-pos) + (back-to-indentation)))) + +(defun gpolonkai/move-to-end-of-line () + "Move to the end of the line. + +If `visual-line-mode' is active, jump to the end of the visual +line first. Then jump to the actual end of the line." + (interactive) + (let ((last-pos (point))) + (when visual-line-mode + (end-of-visual-line)) + (when (= (point) last-pos) + (end-of-line)) + (when (and (eq major-mode 'org-mode) + (= (point) last-pos)) + (org-end-of-line)))) + +(defun gpolonkai/goto-next-char (chr) + "Move toe the next occurence of CHR on the same line." + (interactive "c") + (when (search-forward (char-to-string chr) (pos-eol) t) + (backward-char))) + +(defun gpolonkai/beginning-of-next-word () + "Move to the beginning of the next word." + (interactive) + (let ((current-point (point))) + (forward-word 1) + (backward-word 1) + + (when (<= (point) current-point) + (forward-word 2) + (backward-word 1)))) + +(provide 'gpolonkai/nav-utils) + +;;; nav-utils.el ends here