6
6
; ; Version: 6.0.7
7
7
; ; Author: Phil Hagelberg, Doug Alcorn, and Will Farrington
8
8
; ; Maintainer: Chen Bin <chenbin.sh@gmail.com>
9
- ; ; URL: https://github.com/technomancy /find-file-in-project
9
+ ; ; URL: https://github.com/redguardtoo /find-file-in-project
10
10
; ; Package-Requires: ((emacs "25.1"))
11
11
; ; Created: 2008-03-18
12
12
; ; Keywords: project, convenience
149
149
; ;
150
150
; ; This program works on Windows/Cygwin/Linux/macOS
151
151
; ;
152
- ; ; See https://github.com/technomancy /find-file-in-project for advanced tips.
152
+ ; ; See https://github.com/redguardtoo /find-file-in-project for advanced tips.
153
153
154
154
; ;; Code:
155
155
@@ -198,6 +198,11 @@ It's used by `find-file-with-similar-name'."
198
198
:group 'ffip
199
199
:type 'regexp )
200
200
201
+ (defcustom ffip-git-command " git"
202
+ " The command to use to run diff."
203
+ :group 'ffip
204
+ :type 'string )
205
+
201
206
(defvar ffip-diff-find-file-before-hook nil
202
207
" Hook before `ffip-diff-find-file' move focus out of *ffip-diff* buffer." )
203
208
@@ -211,30 +216,26 @@ The file path is passed to the hook as the first argument.")
211
216
(defvar ffip-relative-path-pattern " ^\\ (\\ .\\ .*/\\ )+"
212
217
" Pattern of relative path." )
213
218
214
- (defun ffip-shell-command-to-string (command )
215
- " Execute shell COMMAND and return its output as a string."
216
- (with-output-to-string
217
- (with-current-buffer
218
- standard-output
219
- (shell-command command t ))))
220
-
221
219
(defun ffip-nonempty-lines (str )
222
220
" Return non empty lines from STR."
223
221
(split-string str " [\r\n ]+" t ))
224
222
225
223
(defun ffip-diff-git-versions ()
226
224
" List all versions of code under Git."
227
- (let* ((git-cmd (concat " git --no-pager log --date=short --pretty=format:'%h|%ad|%s|%an' "
228
- buffer-file-name)))
229
- (nconc (ffip-nonempty-lines (shell-command-to-string " git branch --no-color --all" ))
230
- (ffip-nonempty-lines (shell-command-to-string git-cmd)))))
225
+ (let* ((cmd1 (format " %s branch --no-color --all" ffip-git-command))
226
+ (cmd2 (format " %s --no-pager log --date=short --pretty=format:'%h |%a d|%s |%a n' \" %s \" "
227
+ ffip-git-command
228
+ buffer-file-name)))
229
+ (nconc (ffip-nonempty-lines (shell-command-to-string cmd1))
230
+ (ffip-nonempty-lines (shell-command-to-string cmd2)))))
231
231
232
232
;;;### autoload
233
233
(defun ffip-git-diff-current-file ()
234
234
" Run 'git diff version:current-file current-file'."
235
235
(let* ((default-directory (locate-dominating-file default-directory " .git" ))
236
236
(line (completing-read " diff current file: " (ffip-diff-git-versions))))
237
- (ffip-shell-command-to-string (format " git --no-pager diff %s :%s %s "
237
+ (shell-command-to-string (format " %s --no-pager diff %s :%s %s "
238
+ ffip-git-command
238
239
(replace-regexp-in-string " ^ *\\ *? *" " " (car (split-string line " |" t )))
239
240
(file-relative-name buffer-file-name default-directory)
240
241
buffer-file-name))))
@@ -243,20 +244,24 @@ The file path is passed to the hook as the first argument.")
243
244
" Run 'git diff version' in project."
244
245
(let* ((default-directory (locate-dominating-file default-directory " .git" ))
245
246
(line (completing-read " diff current file: " (ffip-diff-git-versions)))
246
- (version (replace-regexp-in-string " ^ *\\ *? *" " " (car (split-string line " |" t )))))
247
- (ffip-shell-command-to-string (format " git --no-pager diff %s " version))))
247
+ (version (replace-regexp-in-string " ^ *\\ *? *"
248
+ " "
249
+ (car (split-string line " |" t )))))
250
+ (shell-command-to-string (format " %s --no-pager diff %s "
251
+ ffip-git-command
252
+ version))))
248
253
249
254
(defvar ffip-diff-backends
250
255
'(ffip-git-diff-current-file
251
256
ffip-git-diff-project
252
257
(" `git diff HEAD^` in project" . " cd $(git rev-parse --show-toplevel) && git diff HEAD^" )
253
258
(" `git diff --cached` in project" . " cd $(git rev-parse --show-toplevel) && git diff --cached" )
254
259
(" `git diff` in project" . " cd $(git rev-parse --show-toplevel) && git diff" )
255
- (" `git diff` current file" . (ffip- shell-command-to-string (format " cd $(git rev-parse --show-toplevel) && git diff '%s ' "
260
+ (" `git diff` current file" . (shell-command-to-string (format " cd $(git rev-parse --show-toplevel) && git diff '%s ' "
256
261
(buffer-file-name ))))
257
- (" `git log -p` current file" . (ffip- shell-command-to-string (format " cd $(git rev-parse --show-toplevel) && git --no-pager log --date=short -p '%s ' "
262
+ (" `git log -p` current file" . (shell-command-to-string (format " cd $(git rev-parse --show-toplevel) && git --no-pager log --date=short -p '%s ' "
258
263
(buffer-file-name ))))
259
- (" `git log -S keyword -p` in project" . (ffip- shell-command-to-string (format " cd $(git rev-parse --show-toplevel) && git --no-pager log --date=short -S'%s ' -p "
264
+ (" `git log -S keyword -p` in project" . (shell-command-to-string (format " cd $(git rev-parse --show-toplevel) && git --no-pager log --date=short -S'%s ' -p "
260
265
(read-string " Git search string: " ))))
261
266
(" Diff from `kill-ring' " . (car kill-ring)))
262
267
" The list of back-ends.
@@ -713,7 +718,7 @@ IF FIND-DIRECTORY-P is t, we are searching directories, else files."
713
718
(let* ((default-directory (ffip-get-project-root-directory))
714
719
(cmd (ffip-create-shell-command keyword find-directory-p))
715
720
(fd-file-pattern (concat " ^" (mapconcat 'ffip-glob-to-regex ffip-patterns " \\ |" ) " $" ))
716
- (collection (split-string (ffip- shell-command-to-string cmd) " [\r\n ]+" t ))
721
+ (collection (split-string (shell-command-to-string cmd) " [\r\n ]+" t ))
717
722
rlt)
718
723
719
724
(if ffip-debug (message " run command at %s : %s " default-directory cmd))
@@ -1201,7 +1206,7 @@ If OPEN-ANOTHER-WINDOW is not nil, the file will be opened in new window."
1201
1206
(cond
1202
1207
; ; shell command
1203
1208
((stringp backend)
1204
- (ffip-show-content-in-diff-mode (ffip- shell-command-to-string backend)))
1209
+ (ffip-show-content-in-diff-mode (shell-command-to-string backend)))
1205
1210
; ; command
1206
1211
((functionp backend)
1207
1212
(ffip-show-content-in-diff-mode (funcall backend)))
0 commit comments