2010-02-19 40 views
9

Khi tôi sử dụng grep - find, nó sẽ mở ra một cửa sổ khác (khu vực trong khung) với danh sách các kết quả mà tôi có thể chọn. Khi tôi chọn một nó mở tập tin mục tiêu trong một cửa sổ khác với grep -. find là trongLàm cách nào để thực thi liên kết emacs grep-find trong cùng một cửa sổ?

Làm thế nào tôi có thể nhận được các tập tin mục tiêu để mở trong cửa sổ tương tự như grep kết quả (thay thế cửa sổ grep kết quả với những gì tôi đang thực sự tìm kiếm).

Làm thế nào tôi có thể giữ cho grep tìm thấy từ việc mở một cửa sổ riêng biệt (có nó để nó mở ra trong cửa sổ hiện tại). Mục tiêu của tôi là tôi tìm kiếm một cái gì đó, tôi tìm thấy nó, tôi đi đến nó, tất cả trong cùng một cửa sổ. Tôi muốn thêm tệp này vào tệp .emacs của mình.

Trả lời

6

Dường như không có cách nào để định cấu hình gói compile để thực hiện những gì bạn đang yêu cầu. Và không có cách nào dễ dàng để sử dụng advice để tinh chỉnh hành vi. Tôi nghĩ rằng bạn phải nghỉ mát để chỉnh sửa các chức năng mà thực sự nhảy vào lỗi mà bạn có thể làm với việc bổ sung sau vào emacs của bạn (thử nghiệm trong Emacs 23,1):

(eval-after-load "compile" 
'(defun compilation-goto-locus (msg mk end-mk) 
    "Jump to an error corresponding to MSG at MK. 
All arguments are markers. If END-MK is non-nil, mark is set there 
and overlay is highlighted between MK and END-MK." 
    ;; Show compilation buffer in other window, scrolled to this error. 
    (let* ((from-compilation-buffer (eq (window-buffer (selected-window)) 
        (marker-buffer msg))) 
    ;; Use an existing window if it is in a visible frame. 
    (pre-existing (get-buffer-window (marker-buffer msg) 0)) 
    (w (if (and from-compilation-buffer pre-existing) 
     ;; Calling display-buffer here may end up (partly) hiding 
     ;; the error location if the two buffers are in two 
     ;; different frames. So don't do it if it's not necessary. 
     pre-existing 
     (let ((display-buffer-reuse-frames t) 
     (pop-up-windows t)) 
     ;; Pop up a window. 
     (display-buffer (marker-buffer msg))))) 
    (highlight-regexp (with-current-buffer (marker-buffer msg) 
      ;; also do this while we change buffer 
      (compilation-set-window w msg) 
      compilation-highlight-regexp))) 
;; Ideally, the window-size should be passed to `display-buffer' (via 
;; something like special-display-buffer) so it's only used when 
;; creating a new window. 
(unless pre-existing (compilation-set-window-height w)) 

(switch-to-buffer (marker-buffer mk)) 

    ;; was 
;; (if from-compilation-buffer 
;;  ;; If the compilation buffer window was selected, 
;;  ;; keep the compilation buffer in this window; 
;;  ;; display the source in another window. 
;;  (let ((pop-up-windows t)) 
;;  (pop-to-buffer (marker-buffer mk) 'other-window)) 
;; (if (window-dedicated-p (selected-window)) 
;;  (pop-to-buffer (marker-buffer mk)) 
;;  (switch-to-buffer (marker-buffer mk)))) 
;; If narrowing gets in the way of going to the right place, widen. 
(unless (eq (goto-char mk) (point)) 
    (widen) 
    (goto-char mk)) 
(if end-mk 
    (push-mark end-mk t) 
    (if mark-active (setq mark-active))) 
;; If hideshow got in the way of 
;; seeing the right place, open permanently. 
(dolist (ov (overlays-at (point))) 
    (when (eq 'hs (overlay-get ov 'invisible)) 
    (delete-overlay ov) 
    (goto-char mk))) 

(when highlight-regexp 
    (if (timerp next-error-highlight-timer) 
     (cancel-timer next-error-highlight-timer)) 
    (unless compilation-highlight-overlay 
    (setq compilation-highlight-overlay 
     (make-overlay (point-min) (point-min))) 
    (overlay-put compilation-highlight-overlay 'face 'next-error)) 
    (with-current-buffer (marker-buffer mk) 
    (save-excursion 
     (if end-mk (goto-char end-mk) (end-of-line)) 
     (let ((end (point))) 
    (if mk (goto-char mk) (beginning-of-line)) 
    (if (and (stringp highlight-regexp) 
     (re-search-forward highlight-regexp end t)) 
     (progn 
      (goto-char (match-beginning 0)) 
      (move-overlay compilation-highlight-overlay 
       (match-beginning 0) (match-end 0) 
       (current-buffer))) 
     (move-overlay compilation-highlight-overlay 
      (point) end (current-buffer))) 
    (if (or (eq next-error-highlight t) 
     (numberp next-error-highlight)) 
     ;; We want highlighting: delete overlay on next input. 
     (add-hook 'pre-command-hook 
       'compilation-goto-locus-delete-o) 
     ;; We don't want highlighting: delete overlay now. 
     (delete-overlay compilation-highlight-overlay)) 
    ;; We want highlighting for a limited time: 
    ;; set up a timer to delete it. 
    (when (numberp next-error-highlight) 
     (setq next-error-highlight-timer 
     (run-at-time next-error-highlight nil 
       'compilation-goto-locus-delete-o))))))) 
(when (and (eq next-error-highlight 'fringe-arrow)) 
    ;; We want a fringe arrow (instead of highlighting). 
    (setq next-error-overlay-arrow-position 
    (copy-marker (line-beginning-position))))))) 

Phần eval-afer-load chỉ đảm bảo rằng bạn xác định lại nó sau Emacs đã xác định nó, để thay đổi của bạn bị giữ lại.

+0

Thank you very much, Trey! Bạn đã cứu ngày của tôi. –

+0

Trey, Có thể tinh chỉnh chức năng của bạn để giữ Shift-click chuột trong cùng một bộ đệm so với giữ cùng một hành vi nhấp chuột để mở trong một cửa sổ riêng biệt không? – SFbay007

+1

@Ammari Không đáng kể. Cách tiếp cận hack sẽ là có một ràng buộc mới cho Shift-chuột để thiết lập cục bộ một biến '(let ((use-same-window t)) ...)' và sau đó đưa ra lệnh để nhảy tới lỗi, và trong các chức năng trên, chọn hành vi mà bạn muốn. –

1

Bạn có thể thêm một ràng buộc (ví dụ Alt-m) và làm như sau

(define-key grep-mode-map "\M-m" (lambda() 
            (interactive) 
            (compile-goto-error) 
            (delete-other-windows) 
            (kill-buffer "*grep*"))) 

tôi không tìm thấy một cách để thay thế tiêu chuẩn "Enter"/Chuột nhấp chuột ràng buộc với một chức năng tùy chỉnh

+1

liên kết nhập/nhấp chuột chuẩn là thuộc tính văn bản của chuỗi con đó của bộ đệm, bạn có thể chỉnh sửa thuộc tính đó hoặc thay đổi cách biên dịch thêm thuộc tính –

1

có một cách tiếp cận khác:

(defun eab/compile-goto-error() 
    (interactive) 
    (let ((cwc (current-window-configuration))) 
    (funcall 
    `(lambda() 
     (defun eab/compile-goto-error-internal() 
      (let ((cb (current-buffer)) 
       (p (point))) 
      (set-window-configuration ,cwc) 
      (switch-to-buffer cb) 
      (goto-char p)))))) 
    (compile-goto-error) 
    (run-with-timer 0.01 nil 'eab/compile-goto-error-internal)) 
Các vấn đề liên quan