Skip to content

Commit

Permalink
When point is on a line number, go the column offset
Browse files Browse the repository at this point in the history
Closes #112
  • Loading branch information
Wilfred committed Apr 8, 2024
1 parent de1ade7 commit 77ac92d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ To restore the old keybindings:
(define-key deadgrep-mode-map (kbd "P") #'deadgrep-backward-match)
```

Pressing RET on a column number now moves point directly the match,
not just the beginning of the line.

Deadgrep now includes `--no-config` in its default arguments, so
creating a `~/.ripgreprc` will not break deadgrep searches.

Expand Down
17 changes: 13 additions & 4 deletions deadgrep.el
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,8 @@ underlying file."
(when (eq major-mode 'deadgrep-edit-mode)
(save-mark-and-excursion
(goto-char beg)
(-let* ((column (+ (deadgrep--current-column) length))
(-let* ((column (+ (or (deadgrep--current-column) 0)
length))
(filename (deadgrep--filename))
(line-number (deadgrep--line-number))
((buf . opened) (deadgrep--find-file filename))
Expand Down Expand Up @@ -1130,9 +1131,9 @@ In this example, the column is 1."
(while (not (equal (point) line-start))
(cl-incf char-count)
(backward-char 1)))
(max
(- char-count line-number-width)
0)))
(if (< char-count line-number-width)
nil
(- char-count line-number-width))))

(defun deadgrep--flash-column-offsets (start end)
"Temporarily highlight column offset from START to END."
Expand Down Expand Up @@ -1222,6 +1223,14 @@ If POS is nil, use the beginning position of the current line."
(goto-char (point-min))

(when line-number
;; If point was on the line number rather than a specific
;; position on the line, go the first match. This is generally
;; what users want, especially when there are long lines.
(unless column-offset
(if-let (first-match-pos (car match-positions))
(setq column-offset (car first-match-pos))
(setq column-offset 0)))

(-let [destination-pos (deadgrep--buffer-position
line-number column-offset)]
;; Put point on the position of the match, widening the
Expand Down

0 comments on commit 77ac92d

Please sign in to comment.