de-vraag
  • 質問
  • タグ
  • ユーザー
通知:
報酬:
登録
登録すると、質問に対する返答やコメントが通知されます。
ログイン
すでにアカウントをお持ちの方は、ログインして新しい通知を確認してください。
追加された質問、回答、コメントには報酬があります。
さらに
ソース
編集
ゲストユーザ
質問

バッファに `diff`出力を正しくキャプチャするにはどうしたらいいですか?

概要

ファイル名= *。diff に diff の出力をキャプチャしてそのファイルをバッファに開くと、きれいにフォーマットされたmode = Diff 。最初にファイルに取り込むことなく、直接取得する方法は?

詳細

ediff-buffers (私が気に入っている)だけでなく、 diff のようなもっとわかりにくい目的のために、 diff プロセス。私は数十年前からEmacsを使ってきましたが、新しい側面や使い方を学び続けています。だから、私が(ローカルの git リポジトリのdir /フォルダから)それを見つけたのが面白いほど驚くことではありませんでした。

$ git diff master origin/master > /tmp/foo__local_vs_remote.diff

バッファにファイルをオープンしたとき、それはきれいに/有益に色分けされた( ediff )mode = Diffで表示されました。私は今までに一度もなかった

  1. captured diff output to a file
  2. named the file *.diff
  3. opened the file in Emacs

しかし、今私は diff の出力をバッファーと出力を幸福モード= Diffのようにキャプチャしようとしていますが、失敗しています。

一般性を追求する

Note also that, since I use diff in lots of contexts, I'm looking for a solution to the general problem, and not, e.g., just to the git diff problem (which I suspect Magit etc have solved). 一般性を追求する, I'll test 3 usecases: "normal" file-vs-file diff, git diff, and process-substitution diff.

プラットフォーム

$ lsb_release -ds
LMDE 2 Betsy
$ cat /etc/debian_version
8.3
$ uname -rv
3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u4 (2016-02-29)
$ emacs --version
GNU Emacs 24.4.1

オプション

シェルコマンド

私が次のことをした場合(おそらく適切な作業ディレクトリを持つバッファに移動した後に)

  1. M-!
  2. C-x b *Shell Command Output* (where the output of M-!==M-x シェルコマンド goes by default)
  3. M-x diff-mode

...うまくフォーマットされた出力が得られます。さらに

  • これは3つのテストケース全てに適用されます。
  • M - !を別の diff コマンドで実行すると、新しい出力は古いものを上書きしますが、バッファは diff-mode ユーザーの介入なしに
  • キーバインドの変更はありません(用語モードと同様)

選ばれた答え。

シェルモード

もし私が

  1. M-x shell, goto the correct dir/folder, and run git diff master origin/master
  2. am in a buffer on the correct dir/folder, and run M-& git diff master origin/master

私は恐ろしい WARNING:端末が完全に機能していないを得る。

用語モード

Emacs Userが指摘するように、 Mx term は git diff master origin/master を実行すると、出力がうまく色づけされます。それはちょうどmode = Diffではないが、それは仕事をする。残念ながら

  • That only works for git diff: I get no colorization for either process-substitution or file diff.
  • I find the 用語モード keybinding changes highly annoying.
  • I also found 用語モード navigation odd: when editing history, my cursor would sometimes bounce around oddly. solved).
2 2016-03-04T00:20:04+00:00 2
Emacs
diff
diff-mode
process
John Fiala
4日 3月 2016 в 3:37
2016-03-04T03:37:45+00:00
さらに
ソース
編集
#56789085

あなたはいつもあなたのためのすべての繰り返しステップを行うための関数を書くことができます。これはあなたを開始する必要があります:

(defun diff-generic(command)
  (interactive "sDiff command:")
  (let ((buffer (generate-new-buffer "*diff-generic*")))
    (with-current-buffer buffer (diff-mode))
    (call-process-shell-command command nil buffer 0)
    (switch-to-buffer buffer)))

In general you can do M-x diff to get that diff output for two arbitrary files. More info on that here: (info "(emacs) Diff Mode")

Magitはdiff機能を提供しますが、一般的なemacsの diff-mode とは異なる magit-diff-mode という独自のモードを使用しています。

Also emacs bundled package VC provides diff functionality for version control diffs. Unlike magit it works with backends other than git and uses diff-mode, also you can use ediff. Relevant manual: (info "(emacs) Old Revisions")

3
0
Thomas Myron
4日 3月 2016 в 7:40
2016-03-04T07:40:02+00:00
さらに
ソース
編集
#56789086

試す

  1. M-!
  2. C-x b *Shell Command Output* (where the output of M-!==M-x shell-command goes by default)
  3. M-x diff-mode
2
0
質問の追加
カテゴリ
すべて
技術情報
文化・レクリエーション
生活・芸術
科学
プロフェッショナル
事業内容
ユーザー
すべて
新しい
人気
1
Roxana Elizabeth CASTILLO Avalos
登録済み 1週間前
2
Hideo Nakagawa
登録済み 1週間前
3
Sergiy Tytarenko
登録済み 1週間前
4
shoxrux azadov
登録済み 1週間前
5
Koreets Koreytsev
登録済み 2週間前
© de-vraag :年
ソース
emacs.stackexchange.com
ライセンス cc by-sa 3.0 帰属