Skip to content

Commit e996da1

Browse files
author
Chen Bin
committed
clean code&doc
1 parent cde02e5 commit e996da1

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

‎README.org

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Diff/patch files. Target files could be under any Version Control Software (VCS)
1919

2020
*Screenshot:*
2121

22-
[[https://raw.githubusercontent.com/technomancy/find-file-in-project/master/ffip-screenshot-nq8.png]]
22+
[[https://raw.githubusercontent.com/redguardtoo/find-file-in-project/master/ffip-screenshot-nq8.png]]
2323

2424
* Install
25-
Place [[https://raw.githubusercontent.com/technomancy/find-file-in-project/master/find-file-in-project.el][find-file-in-project.el]] under [[https://www.emacswiki.org/emacs/LoadPath][Load Path]]. Then add =(require 'find-file-in-project)= to your configuration.
25+
Place [[https://raw.githubusercontent.com/redguardtoo/find-file-in-project/master/find-file-in-project.el][find-file-in-project.el]] under [[https://www.emacswiki.org/emacs/LoadPath][Load Path]]. Then add =(require 'find-file-in-project)= to your configuration.
2626

2727
It is also possible to use [[http://stable.melpa.org/#/find-file-in-project][melpa]]; however be aware that as of the time of this writing installation using =package.el= is [[https://glyph.twistedmatrix.com/2015/11/editor-malware.html][not recommended]] due to flaws in Emacs's TLS implementation.
2828

@@ -256,7 +256,7 @@ Install [[https://github.com/abo-abo/swiper][counsel]].
256256

257257
Use =counsel-git= to find file and =counsel-git-grep= to grep.
258258
* Bug Report
259-
Check [[https://github.com/technomancy/find-file-in-project]].
259+
Check [[https://github.com/redguardtoo/find-file-in-project]].
260260
* License
261261
This program is free software: you can redistribute it and/or modify it under the terms of the [[file:LICENSE][GNU General Public License]] as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
262262

‎find-file-in-project.el

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; Version: 6.0.7
77
;; Author: Phil Hagelberg, Doug Alcorn, and Will Farrington
88
;; 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
1010
;; Package-Requires: ((emacs "25.1"))
1111
;; Created: 2008-03-18
1212
;; Keywords: project, convenience
@@ -149,7 +149,7 @@
149149
;;
150150
;; This program works on Windows/Cygwin/Linux/macOS
151151
;;
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.
153153

154154
;;; Code:
155155

@@ -198,6 +198,11 @@ It's used by `find-file-with-similar-name'."
198198
:group 'ffip
199199
:type 'regexp)
200200

201+
(defcustom ffip-git-command "git"
202+
"The command to use to run diff."
203+
:group 'ffip
204+
:type 'string)
205+
201206
(defvar ffip-diff-find-file-before-hook nil
202207
"Hook before `ffip-diff-find-file' move focus out of *ffip-diff* buffer.")
203208

@@ -211,30 +216,26 @@ The file path is passed to the hook as the first argument.")
211216
(defvar ffip-relative-path-pattern "^\\(\\.\\.*/\\)+"
212217
"Pattern of relative path.")
213218

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-
221219
(defun ffip-nonempty-lines (str)
222220
"Return non empty lines from STR."
223221
(split-string str "[\r\n]+" t))
224222

225223
(defun ffip-diff-git-versions ()
226224
"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|%ad|%s|%an' \"%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)))))
231231

232232
;;;###autoload
233233
(defun ffip-git-diff-current-file ()
234234
"Run 'git diff version:current-file current-file'."
235235
(let* ((default-directory (locate-dominating-file default-directory ".git"))
236236
(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
238239
(replace-regexp-in-string "^ *\\*? *" "" (car (split-string line "|" t)))
239240
(file-relative-name buffer-file-name default-directory)
240241
buffer-file-name))))
@@ -243,20 +244,24 @@ The file path is passed to the hook as the first argument.")
243244
"Run 'git diff version' in project."
244245
(let* ((default-directory (locate-dominating-file default-directory ".git"))
245246
(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))))
248253

249254
(defvar ffip-diff-backends
250255
'(ffip-git-diff-current-file
251256
ffip-git-diff-project
252257
("`git diff HEAD^` in project" . "cd $(git rev-parse --show-toplevel) && git diff HEAD^")
253258
("`git diff --cached` in project" . "cd $(git rev-parse --show-toplevel) && git diff --cached")
254259
("`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'"
256261
(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'"
258263
(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"
260265
(read-string "Git search string: "))))
261266
("Diff from `kill-ring'" . (car kill-ring)))
262267
"The list of back-ends.
@@ -713,7 +718,7 @@ IF FIND-DIRECTORY-P is t, we are searching directories, else files."
713718
(let* ((default-directory (ffip-get-project-root-directory))
714719
(cmd (ffip-create-shell-command keyword find-directory-p))
715720
(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))
717722
rlt)
718723

719724
(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."
12011206
(cond
12021207
;; shell command
12031208
((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)))
12051210
;; command
12061211
((functionp backend)
12071212
(ffip-show-content-in-diff-mode (funcall backend)))

0 commit comments

Comments
 (0)