153153 (ivy-file-preview--make-overlay pos (+ pos len)))))
154154
155155(defun ivy-file-preview--open-file (fn pos )
156- " Open the file path (FN).
157- POS can either be an integer or cons cell represent line number and columns."
158- (setq ivy-file-preview--selected-file fn)
159- (if (file-exists-p fn) (find-file fn) (switch-to-buffer fn))
160- (cond ((consp pos)
161- (ivy-file-preview--goto-line (car pos))
162- (move-to-column (cdr pos)))
163- ((integerp pos) (goto-char (1+ pos)))
164- (t (error " Invalid position details: %s " pos))))
165-
166- (defun ivy-file-preview--do-preview (project-dir fn pos )
156+ " Open the file path (FN) and move to POS.
157+ If POS is nil then it won't moves."
158+ (let ((is-fild-p t ))
159+ (cond ((file-exists-p fn) (find-file fn))
160+ ((not ivy-file-preview-details) (setq is-fild-p nil ))
161+ (t (switch-to-buffer fn)))
162+ (when is-fild-p
163+ (setq ivy-file-preview--selected-file fn)
164+ (cond ((consp pos)
165+ (ivy-file-preview--goto-line (car pos))
166+ (move-to-column (cdr pos)))
167+ ((integerp pos) (goto-char (1+ pos)))
168+ ((not pos) (goto-char (point-min )))
169+ (t (error " Invalid position details: %s " pos))))))
170+
171+ (defun ivy-file-preview--do-preview (fn pos )
167172 " Do file preview execution.
168- FN is the file path. PROJECT-DIR is the path of the project root directory.
169- POS can either be an integer or cons cell represent line number and columns."
173+ FN is the file path. POS can either be one of the following type:
174+ * integer : Position in file.
175+ * cons cell : Contain two integer. (line-number & column)
176+ * nil : Just open it without moving the point."
170177 (save-selected-window
171178 (with-selected-window minibuffer-scroll-window
172- (when project-dir (setq fn (f-join project-dir fn)))
173179 (when (and ivy-file-preview-preview-only
174180 (not (find-buffer-visiting fn))
175181 (buffer-file-name ))
176182 (push fn ivy-file-preview--preview-files))
177183 (unless (string= ivy-file-preview--selected-file fn)
178184 (ivy-file-preview--delete-overlays))
179185 (ivy-file-preview--open-file fn pos)
180- (when ivy-file-preview-overlay-p
186+ (when ( and ivy-file-preview-overlay-p ivy-file-preview-details)
181187 (ivy-file-preview--delete-overlays)
182188 (ivy-file-preview--make-overlays)))))
183189
@@ -191,13 +197,14 @@ POS can either be an integer or cons cell represent line number and columns."
191197 (cands (ivy-file-preview--candidates))
192198 (current-selection (or (nth ivy--index cands) " " ))
193199 (sel-lst (split-string current-selection " :" ))
194- fn ln cl )
195- ( when ( < 2 ( length sel-lst) )
196- (setq fn ( nth 0 sel-lst) ln ( nth 1 sel-lst) cl ( nth 2 sel-lst) ))
197- (when ( and ivy-file- preview-details ln)
198- (setq ln (string-to-number ln)
200+ ( fn ( nth 0 sel-lst)) ( ln ( nth 1 sel-lst)) ( cl ( nth 2 sel-lst) )
201+ can-preview-p )
202+ (setq can-preview-p ( if ivy-file-preview-details ln t ))
203+ (when can- preview-p
204+ (setq ln (ignore-errors ( cl-parse-integer ln) )
199205 cl (ignore-errors (cl-parse-integer cl)))
200- (ivy-file-preview--do-preview project-dir fn (if cl (cons ln cl) ln))))))
206+ (when project-dir (setq fn (f-join project-dir fn)))
207+ (ivy-file-preview--do-preview fn (if cl (cons ln cl) ln))))))
201208
202209(defun ivy-file-preview--back-to-pos ()
203210 " Back to starting position."
0 commit comments