Skip to content

Commit

Permalink
fix: Navigate pure space character
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jan 3, 2024
1 parent 7102642 commit fae4866
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions block-travel.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@

;;; Code:

(defgroup block-travel nil
"Move to previous/next blank line."
:prefix "block-travel-"
:group 'tool
:link '(url-link :tag "Repository" "https://github.com/jcs-elpa/block-travel"))

(defcustom block-travel-regex "^[[:space:]]*\n"
"Regex to navigate to blank lines."
:type 'string
:group 'block-travel)

;;
;; (@* "Util" )
;;

(defun block-travel--current-line-empty-p ()
"Current line empty, but accept spaces/tabs in there. (not absolute)."
(save-excursion (beginning-of-line) (looking-at "[[:space:]\t]*$")))
(save-excursion (beginning-of-line) (looking-at "[[:space:]]*$")))

;;
;; (@* "Core" )
Expand All @@ -47,15 +58,15 @@
(defun block-travel-up (&optional _)
"Move to the previous line containing nothing but whitespaces or tabs."
(interactive "^P")
(let ((sr-pt (save-excursion (re-search-backward "^[ \t]*\n" nil t))))
(let ((sr-pt (save-excursion (re-search-backward block-travel-regex nil t))))
(goto-char (or sr-pt (point-min)))))

;;;###autoload
(defun block-travel-down (&optional _)
"Move to the next line containing nothing but whitespaces or tabs."
(interactive "^P")
(when (block-travel--current-line-empty-p) (forward-line 1))
(let ((sr-pt (save-excursion (re-search-forward "^[ \t]*\n" nil t))))
(let ((sr-pt (save-excursion (re-search-forward block-travel-regex nil t))))
(goto-char (or sr-pt (point-max)))
(when sr-pt (forward-line -1))))

Expand Down

0 comments on commit fae4866

Please sign in to comment.