1
- ; ;; find-file-in-project.el --- Find file/directory and review Diff/Patch/Commit efficiently -*- coding : utf-8 -*-
1
+ ; ;; find-file-in-project.el --- Find file/directory and review Diff/Patch/Commit efficiently -*- lexical-binding : t -*-
2
2
3
3
; ; Copyright (C) 2006-2009, 2011-2012, 2015-2018
4
4
; ; Phil Hagelberg, Doug Alcorn, Will Farrington, Chen Bin
@@ -788,7 +788,6 @@ If KEYWORD is list, it's the list of file names.
788
788
IF FIND-DIRECTORY-P is t, we are searching directories, else files."
789
789
(let* ((default-directory (ffip-get-project-root-directory))
790
790
(cmd (ffip-create-shell-command keyword find-directory-p))
791
- (fd-file-pattern (concat " ^" (mapconcat 'ffip-glob-to-regex ffip-patterns " \\ |" ) " $" ))
792
791
(collection (funcall ffip-project-search-function cmd))
793
792
rlt)
794
793
@@ -852,7 +851,7 @@ After opening the file, forward LNUM lines."
852
851
If OPEN-ANOTHER-WINDOW is t, the results are displayed in a new window.
853
852
If FIND-DIRECTORY-P is t, only search directories. FN is callback.
854
853
This function is the API to find files."
855
- (let* (cands lnum file )
854
+ (let (cands lnum)
856
855
; ; extract line num if exists
857
856
(when (and keyword (stringp keyword)
858
857
(string-match " ^\\ (.*\\ ):\\ ([0-9]+\\ ):?$" keyword))
@@ -921,8 +920,7 @@ Please note N is zero originated."
921
920
rlt)
922
921
(cond
923
922
((region-active-p )
924
- (setq ffip-filename-history (add-to-list 'ffip-filename-history
925
- (ffip--read-selected)))
923
+ (push (ffip--read-selected) ffip-filename-history)
926
924
(setq rlt (ffip--read-selected)))
927
925
(t
928
926
(setq rlt (read-from-minibuffer hint nil nil nil 'ffip-filename-history ))))
@@ -939,7 +937,7 @@ See (info \"(Emacs) Directory Variables\") for details."
939
937
(concat (file-name-as-directory root) " .dir-locals.el" ))))
940
938
(when file
941
939
(with-temp-buffer
942
- (let ((print-level nil ) (print-length nil ) sexp (rlt '(a)) )
940
+ (let ((print-level nil ) (print-length nil ) sexp)
943
941
(cond
944
942
; ; modify existing .dir-locals.el
945
943
((file-exists-p file)
@@ -956,13 +954,13 @@ See (info \"(Emacs) Directory Variables\") for details."
956
954
(if (assoc 'ffip-project-root sub-sexp)
957
955
(setq new-sub-sexp (delete (assoc 'ffip-project-root sub-sexp) sub-sexp))
958
956
(setq new-sub-sexp sub-sexp))
959
- (add-to-list 'new-sub-sexp (ffip--prepare-root-data-for-project-file root) t )
957
+ (push (ffip--prepare-root-data-for-project-file root) new-sub-sexp )
960
958
; ; update sexp
961
959
(setq sexp (delete sub-sexp sexp))
962
- (add-to-list 'sexp new-sub-sexp))
960
+ (push new-sub-sexp sexp))
963
961
(t
964
962
; ; add `(nil (ffip-project-root . "path/file"))'
965
- (add-to-list 'sexp (list nil (ffip--prepare-root-data-for-project-file root))))))
963
+ (push (list nil (ffip--prepare-root-data-for-project-file root)) sexp ))))
966
964
))
967
965
(t
968
966
; ; a new .dir-locals.el
@@ -1108,8 +1106,7 @@ If OPEN-ANOTHER-WINDOW is not nil, the file will be opened in new window."
1108
1106
" Insert contents of file in current buffer.
1109
1107
The file name is selected interactively from candidates in project."
1110
1108
(interactive )
1111
- (let* ((cands (ffip-project-search (ffip-read-keyword)))
1112
- root)
1109
+ (let* ((cands (ffip-project-search (ffip-read-keyword))))
1113
1110
(when (> (length cands) 0 )
1114
1111
(ffip-completing-read (ffip-hint)
1115
1112
cands
@@ -1394,38 +1391,36 @@ If NUM is not nil, the corresponding backend is executed directly."
1394
1391
(i 0 ))
1395
1392
; ; format backend descriptions
1396
1393
(dolist (b ffip-diff-backends)
1397
- (add-to-list 'descriptions
1398
- (format " %s : %s "
1399
- i
1400
- (ffip-backend-description b)) t )
1394
+ (push (format " %s : %s " i (ffip-backend-description b)) descriptions)
1401
1395
(setq i (+ 1 i)))
1402
1396
(ffip-completing-read
1403
1397
" Run diff backend: "
1404
- descriptions
1398
+ ( nreverse descriptions)
1405
1399
(lambda (file )
1406
1400
(if (string-match " ^\\ ([0-9]+\\ ): " file)
1407
1401
(ffip-show-diff-internal (string-to-number (match-string 1 file))))))))))
1408
1402
1409
1403
;;;### autoload
1410
1404
(defalias 'ffip-show-diff 'ffip-show-diff-by-description )
1411
1405
1412
- (defadvice read-file-name (around ffip-read-file-name-hack activate )
1413
- " Advice `read-file-name' ."
1406
+ (defun ffip-read-file-name-hack ( orig-func &rest args )
1407
+ " Advice `read-file-name' with ORIG-FUNC and ARGS for `ffip-diff-apply-hunk' ."
1414
1408
(cond
1415
1409
(ffip-read-file-name-hijacked-p
1416
1410
; ; only hack read-file-name once
1417
1411
(setq ffip-read-file-name-hijacked-p nil )
1418
- (let* ((args (ad-get-args 0 ))
1419
- (file-name (file-name-nondirectory (nth 2 args)))
1412
+ (let* ((file-name (file-name-nondirectory (nth 2 args)))
1420
1413
(default-directory (ffip-project-root))
1421
1414
(cands (ffip-project-search file-name))
1422
1415
(rlt (if cands (ffip-completing-read " Files: " cands))))
1416
+ (message " file-name=%s " file-name)
1423
1417
(when rlt
1424
1418
(setq rlt (file-truename rlt))
1425
1419
(run-hook-with-args 'ffip-diff-apply-hunk-hook rlt)
1426
- ( setq ad-return-value rlt) )))
1420
+ rlt)))
1427
1421
(t
1428
- ad-do-it)))
1422
+ (apply orig-func args))))
1423
+ (advice-add 'read-file-name :around #'ffip-read-file-name-hack )
1429
1424
1430
1425
;;;### autoload
1431
1426
(defun ffip-diff-apply-hunk (&optional reverse )
0 commit comments