Skip to content

Commit a599a77

Browse files
committed
Compatible to position.
1 parent 06e549a commit a599a77

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

ivy-file-preview.el

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
;;; Code:
3434

35+
(require 'cl-lib)
3536
(require 'f)
3637
(require 'ivy)
3738

@@ -73,23 +74,27 @@
7374

7475
;;; Core
7576

76-
(defun ivy-file-preview--open-file (fn ln cl)
77-
"Open the file (FN), line number (LN), and column (CL)."
77+
(defun ivy-file-preview--open-file (fn pos)
78+
"Open the file path (FN).
79+
POS can either be a integer or cons cell represent line number and columns."
7880
(setq ivy-file-preview--selected-file fn)
7981
(find-file fn)
80-
(ivy-file-preview--goto-line ln)
81-
(move-to-column cl))
82+
(cond ((consp pos)
83+
(ivy-file-preview--goto-line (car pos))
84+
(move-to-column (cdr pos)))
85+
((integerp pos) (goto-char (1+ pos)))
86+
(t (error "Undefined pos details: %s" pos))))
8287

83-
(defun ivy-file-preview--do-preview (fn ln cl project-dir)
88+
(defun ivy-file-preview--do-preview (project-dir fn pos)
8489
"Do file preview execution.
85-
FN represents file path. LN represents line numbers. CL represents columns.
86-
PROJECT-DIR represents the path of the project root directory."
90+
FN is the file path. PROJECT-DIR is the path of the project root directory.
91+
POS can either be a integer or cons cell represent line number and columns."
8792
(save-selected-window
8893
(with-selected-window minibuffer-scroll-window
8994
(when project-dir (setq fn (f-join project-dir fn)))
9095
(when (and ivy-file-preview-preview-only (not (find-buffer-visiting fn)))
9196
(push fn ivy-file-preview--preview-files))
92-
(ivy-file-preview--open-file fn ln cl))))
97+
(ivy-file-preview--open-file fn pos))))
9398

9499
(defun ivy-file-preview--after-select (&rest _)
95100
"Execution after selection."
@@ -100,10 +105,10 @@ PROJECT-DIR represents the path of the project root directory."
100105
fn ln cl)
101106
(when (< 2 (length sel-lst))
102107
(setq fn (nth 0 sel-lst) ln (nth 1 sel-lst) cl (nth 2 sel-lst)))
103-
(when (and ivy-file-preview-details ln cl)
108+
(when (and ivy-file-preview-details ln)
104109
(setq ln (string-to-number ln)
105-
cl (string-to-number cl))
106-
(ivy-file-preview--do-preview fn ln cl project-dir))))
110+
cl (ignore-errors (cl-parse-integer cl)))
111+
(ivy-file-preview--do-preview project-dir fn (if cl (cons ln cl) ln)))))
107112

108113
(defun ivy-file-preview--cancel-revert ()
109114
"Revert frame status if user cancel the commands."

0 commit comments

Comments
 (0)