;;; gpolonkai/magit-utils.el --- Magit related 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: (defun gpolonkai/magit-goto-beginning-of-section () "Go to the beginning of the current Magit section." (interactive) (let ((section (magit-current-section))) (magit-section-goto section))) (defun gpolonkai/magit-goto-end-of-section () "Move to the beginning of the next visible section." (interactive) (unless (eobp) (let ((section (magit-current-section))) (if (oref section parent) (let ((next (and (not (oref section hidden)) (not (= (oref section end) (1+ (point)))) (car (oref section children))))) (while (and section (not next)) (unless (setq next (car (magit-section-siblings section 'next))) (setq section (oref section parent)))) (if next (magit-section-goto next) (end-of-buffer))) (magit-section-goto 1))))) (defun gpolonkai/magit-find-first-link () "Find the first URL in the current section." (interactive) (let ((bos (save-excursion (gpolonkai/magit-goto-beginning-of-section) (point))) (eos (save-excursion (gpolonkai/magit-goto-end-of-section) (point)))) (goto-char bos) (when (re-search-forward "https?://" eos t) (goto-char (match-beginning 0))))) (provide 'gpolonkai/magit-utils) ;;; magit-utils.el ends here