bufferdagi 'diff`li chiqishni to'g'ri qanday olish kerak (birinchi faylni ochmasdan)?

Xulosa

Fayl kodi = *. Diff ga diff chiqadi va bu faylni buferda ochsa, yaxshi formatlangan tartib = Diff . Qanday qilib uni to'g'ridan-to'g'ri, avval faylga tortmasdan olish mumkin?

tafsilotlar

Faqat ediff-buffers (men sevadigan) orqali emas, balki diff ing ning output jarayonlar. Men Emacsni bir necha o'n yillar davomida ishlatganman, lekin yangi aspektlarni o'rganishni davom ettirmoqdaman. Shunday qilib, men buni qilganimda (mahalliy git repo-dagi dir/papkadan)

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

faylni buferda ochdi, u yaxshi/foydali rangli (a la ediff ) tartibida = Diffda ko'rsatildi. Bir vaqtning o'zida hech qachon bo'lmaganman

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

Lekin endi diff chiqishi to'g'ridan-to'g'ri buferdagi va xotirjam rejimiga o'xshash chiqdi olish uchun harakat qilaman = Diff va bajarilmayapti.

odillikni qidirish

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). odillikni qidirish, I'll test 3 usecases: "normal" file-vs-file diff, git diff, and process-substitution diff.

platforma

$ 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

imkoniyatlari

shell-buyruqlar

Quyidagilarni qilsam (ehtimol, tegishli ishchi katalogga ega bo'lgan tamponga o'tishdan keyin)

  1. M-!
  2. C-x b *Shell Command Output* (where the output of M-!==M-x shell-buyruqlar goes by default)
  3. M-x diff-mode

... Men yaxshi formatlangan mahsulotni olaman. Bundan tashqari

  • bu barcha 3 sinov uchun ishlaydi
  • boshqa diff buyrug'i bilan M -! ishlayotgan bo'lsa, yangi chiqish faqat eskisini yozadi, ammo bufer diff-mode foydalanuvchi aralashuvisiz
  • hech qanday keybinding o'zgarishlar (muddat rejimida bo'lgani kabi)

Tanlangan javob.

qobiq rejimi

Men ham

  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

Men qo'rqinchli OGOHLANTIRISH: terminali to'liq ishlamayapti .

muddat rejimi

Emacs Foydalanuvchi tomonidan berilgan ma'lumotlarga qaraganda, Mx termasi bu usecase uchun Mx qobig'i : agar Mx termini bo'lsa, to'g'ri tir/papkaga ega bo'lish va git dif diffrent master origin/master ni ishga tushirib, yaxshi rangli chiqdi olaman. To'liq tartib = Diff emas, lekin bu ishni bajaradi. Afsuski

2

2 javoblar

Siz uchun barcha takrorlangan amallarni bajarish uchun doimo funktsiya yozishingiz mumkin. Buni boshlashingiz kerak:

(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 funksiyasini ta'minlaydi, lekin uni magit-diff-mode deb ataladigan o'z tartibini ishlatishini e'tiborga oling, ya'ni umumiy emacs diff-mode dan farq qiladi.

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
qo'shib qo'ydi
Men sizning javobingizni yangiladim, bu siz istagan narsaga bog'liq.
qo'shib qo'ydi muallif John Fiala, manba
bo'limiga qarang = "qidirib toping". Bu qanday amalga oshiriladi, masalan, jarayonni almashtirish?
qo'shib qo'ydi muallif kraymer, manba

Ushlab ko'ring

  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
qo'shib qo'ydi
Ushbu javobni o'qiganlar ushbu kodni qabul qiladigan echim bilan WARNING: terminal to'liq ishlamaydi yo'qligini bilish kerak. Bu cheklangan farqli ish uchun ishlashi mumkin, lekin agar so'raladigan OP kodi sifatida seekerity bo'lsa, iltimos, to'liq hal sifatida M-x termini dan foydalaning. Nima uchun sabablar bo'yicha Emacs hujjatiga qarang.
qo'shib qo'ydi muallif Emacs User, manba
savol qismini tanlash sabablarini ko'rish = shell-command
qo'shib qo'ydi muallif kraymer, manba