Created
April 3, 2012 04:09
-
-
Save hidsh/2289250 to your computer and use it in GitHub Desktop.
xyzzy: my-grep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; @@@ my-grep | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(provide "my-grep") | |
(require "grep") | |
(require "grepd") | |
(require "errors-mod") | |
(in-package "editor") | |
(export '(*my-grep-ignore-pattern*)) | |
(defun lookup-word-near-cursor () | |
(grep-lookup-word | |
#'(lambda (start end) | |
(let ((word (buffer-substring start end)) | |
; (ext (if (string-match "^[^.]+\\." | |
; (reverse (get-buffer-file-name))) | |
; (reverse (match-string 0)) | |
; "")) | |
; (dir (directory-namestring (get-buffer-file-name)))) | |
) | |
(unless word | |
(seq word "")) | |
word)))) | |
(defun grep-lookup-word (fn) | |
(apply fn (save-excursion | |
(list (progn | |
(skip-syntax-spec-forward "w_") | |
(point)) | |
(progn | |
(skip-syntax-spec-backward "w_") | |
(point)))))) | |
(defun get-buffer-parent-directory () | |
(let ((ret "") | |
(path (get-buffer-file-name))) | |
(if (stringp path) | |
(setq ret (directory-namestring path))) | |
ret)) | |
(defun my-grep-internal-re (directory pattern-files) | |
"moccur style recursive grep command /w regexp" | |
(interactive "DGREP-RE: \nsregexp and filemask:" | |
:default0 (get-buffer-parent-directory) | |
:default1 (concat (lookup-word-near-cursor) "\t*.[ch]")) | |
(let ((ed::*grep-case-fold-search* nil) | |
(ed::*grep-regexp-search* t) ; enable re | |
(ed::*grep-subdir* t) | |
(ed::*grep-name-only* nil)) | |
(let (input) | |
(setq input (split-string pattern-files "\t")) | |
(setq pattern (car input)) | |
(setq files (car (cdr input)))) | |
(ed::scan-files pattern files directory) ;; exec-grep | |
(setq buffer-read-only t) | |
(next-line 1) | |
;; (c-mode) | |
)) | |
(defun my-grep-internal-fixed (directory pattern-files) | |
"moccur style recursive grep command /w fixed string" | |
(interactive "DGREP-FIX: \nsstring and filemask:" | |
:default0 (get-buffer-parent-directory) | |
:default1 (concat (lookup-word-near-cursor) "\t*.[ch]")) | |
(let ((ed::*grep-case-fold-search* nil) | |
(ed::*grep-regexp-search* nil); disable re | |
(ed::*grep-subdir* t) | |
(ed::*grep-name-only* nil)) | |
(let (input) | |
(setq input (split-string pattern-files "\t")) | |
(setq pattern (car input)) | |
(setq files (cond ((car (cdr input))) | |
("*")))) | |
(ed::scan-files pattern files directory) ;; exec-grep | |
(setq buffer-read-only t) | |
(next-line 1) | |
;; (c-mode) | |
)) | |
(defun my-grep (&optional arg) | |
(interactive "p") | |
(if arg | |
(call-interactively 'my-grep-internal-re) | |
(call-interactively 'my-grep-internal-fixed))) | |
;; http://se-suganuma.blogspot.com/2007/12/xyzzygrep.html | |
;;対象外にするフォルダ | |
(defvar *my-grep-ignore-pattern* '("dic/" "\\.svn/")) | |
;; add to .xyzzy | |
;; (setq *my-grep-ignore-pattern* '("dic/" "\\.svn/" | |
;; "\\.jar$")) | |
;; 元の関数 | |
(defvar *scan-files-1-orig* (function ed::scan-files-1)) | |
(defun ed::scan-files-1 (path pattern buffer scanner) | |
(unless (find-if #'(lambda (ig) (string-match ig path)) *my-grep-ignore-pattern*) | |
(funcall *scan-files-1-orig* path pattern buffer scanner))) | |
;; global-keybind | |
(global-set-key #\M-o 'my-grep) | |
(export '(*grep-map*)) | |
(defvar *grep-map* nil) | |
(unless *grep-map* | |
(setq *grep-map* (make-sparse-keymap))) | |
(define-key *grep-map* #\RET 'first-error-gnrr) | |
;; (add-hook 'ed::*grep-hook* #'(lambda () (use-keymap *grep-map*))) | |
;; (add-hook 'ed::*grep-hook* #'(lambda () (setq buffer-read-only t))) | |
;; (add-hook 'ed::*grepd-hook* #'(lambda () (use-keymap *grep-map*))) | |
;; (add-hook 'ed::*grepd-hook* #'(lambda () (setq buffer-read-only t))) | |
;; color | |
;; (setq-default *grep-highlight-match* '(:bold t :background 6)) | |
(setq-default *grep-highlight-match* '(:background 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment