Frage

Ich beginne mit Emacs, und weiß nicht viel elisp. Fast nichts, wirklich.

Ich möchte als Ersatz von grep ack verwenden.

Das sind die Anweisungen, die ich gefolgt von Emacs zu verwenden ack: http://www.rooijan.za.net/?q=ack_el

Jetzt mache ich nicht wie das Ausgabeformat, das in dieser el-Datei verwendet wird, würde ich die Ausgabe wie die von ack --group zu sein.

Also habe ich geändert:

(read-string "Ack arguments: " "-i" nil "-i" nil)

zu:

(read-string "Ack arguments: " "-i --group" nil "-i --group" nil)

So weit, so gut. Aber das hat mich die Fähigkeit verlieren, zu Klick press_enter auf den Zeilen des Ausgangspuffers. Im ursprünglichen Verhalten wurde die Kompilierung-Modus verwendet, um die ausgewählten Zeile springen zu können.

Ich dachte, ich sollte eine regexp zum ack-Modus hinzufügen. Der ack-Modus wird wie folgt definiert:

(define-compilation-mode ack-mode "Ack"
  "Specialization of compilation-mode for use with ack."
   nil)

und ich mag die regexp [0-9]+: hinzufügen zu als Fehler erkannt werden, da es ist, was jede Zeile der Ausgabe bugger enthält (Zeilennummer).

Ich habe versucht, die define-compilation-modeabove zu modifizieren, um die regexp hinzuzufügen, aber ich kläglich gescheitert.

Wie kann ich den Ausgabepuffer von ack machen lassen Sie mich auf seine Zeilen klicken?

--- EDIT, ich habe auch versucht: ---

(defvar ack-regexp-alist 
    '(("[0-9]+:"
     2 3))
  "Alist that specifies how to match rows in ack output.")

(setq compilation-error-regexp-alist
      (append compilation-error-regexp-alist
          ack-regexp-alist))

stahl ich, dass irgendwo und versuchte, auf meine Bedürfnisse anzupassen. Kein Glück.

--- EDIT, Ergebnis nach Ivan Vorschlag ---

Mit ack.el aktualisiert, um:

(defvar ack-regexp-alist 
  '(("^[0-9]+:" ;; match the line number
     nil        ;; the file is not found on this line, so assume that it's the same as before
     0          ;; The line is the 0'th subexpression (the whole thing)
     )
    ("^[^: ]+$" ;; match a file -- this could be better
     0          ;; The file is the 0'th subexpression
     ))
  "Alist that specifies how to match rows in ack output.")

(setq compilation-error-regexp-alist
      (append compilation-error-regexp-alist
          ack-regexp-alist))


(define-compilation-mode ack-mode "Ack"
  "Specialization of compilation-mode for use with ack."
   nil) 

Überprüfen Sie dann die compilation-error-regext-alist Variable, erhalte ich den Wert:

(absoft ada aix ant bash borland caml comma edg-1 edg-2 epc ftnchek iar ibm irix java jikes-file jikes-line gnu gcc-include lcc makepp mips-1 mips-2 msft oracle perl rxp sparc-pascal-file sparc-pascal-line sparc-pascal-example sun sun-ada 4bsd gcov-file gcov-header gcov-nomark gcov-called-line gcov-never-called
        ("^[0-9]+:" nil 0)
        ("^[^: ]+$" 0))

Ich finde das Format der Variablen sehr seltsam, ist es nicht? Ich weiß nicht, elisp (noch) nicht, vielleicht ist es richtig, dass Art und Weise.

Noch keine Links oder Farbe im * ack * puffern.

War es hilfreich?

Lösung

Es gibt ein weiteres full-ack Paket oben auf ELPA , die ich verwendet habe, bevor und Griffe Ausgabe --group.

Das heißt, in der Dokumentation zu compilation-error-regexp-alist Lesen Sie sehen, dass es die Form hat:

(REGEXP FILE [LINE COLUMN TYPE HYPERLINK HIGHLIGHT...])

Im Fall von --group Ausgang, müssen Sie separat Datei und Zeile passen, so dass ich glaube, Sie wollen so etwas wie (ungetestet)

(defvar ack-regexp-alist
  '(("^\\S +$" ;; match a file -- this could be better
     0          ;; The file is the 1st subexpression
     )
    ("^[0-9]+:" ;; match the line number
     nil        ;; the file is not found on this line, so assume that it's the same as before
     0          ;; The line is the 0'th subexpression (the whole thing)
     ))
  "Alist that specifies how to match rows in ack output.")

- Aktualisiert -

Die Variable compilation-error-regext-alist ist eine Liste von Symbolen oder Elementen wie (REGEXP ...). Die Symbole werden in compilation-error-regexp-alist-alist nachgeschlagen die entsprechenden Elemente zu finden. Also ja, es ist ein wenig seltsam, aber es ist einfacher zu sehen, was ein- und ausgeschaltet ist, ohne hässliche reguläre Ausdrücke suchen zu müssen und erraten, was sie tun. Wenn Sie dies verteilen würden würde ich vorschlagen, die Regex zu compilation-error-regexp-alist-alist Hinzufügen und dann auf in compilation-error-regext-alist drehen, aber das ist etwas strittig, bis Sie es richtig zu arbeiten.

Bei genauerer Betrachtung ack.el, merke ich, dass es verwendet

(let (compile-command
      (compilation-error-regexp-alist grep-regexp-alist)
      ...)
  ...
  )

Mit anderen Worten lokal überschrieben compilation-error-regexp-alist mit grep-regexp-alist, so dass Sie die reguläre Ausdrücke dort statt hinzufügen müssen. Oder noch besser sein könnte, ersetzen es mit

(let (compile-command
      (compilation-error-regexp-alist ack-regexp-alist)
      ...)
  ...
  )

Am Ende habe ich noch empfehlen Voll ack da der Dateiname regex tut nicht scheint, richtig zu funktionieren. Es scheint, vollständigere (obwohl mehr kompliziert), und ich habe mit ihm glücklich.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top