Windows 10, Emacs 25.1, Magit

Execute command magit-status and press "TAB". Here result:


If I want to change this text I go to my editor (e.g. Notepad++) and edit text.

The question is:

Can I directy edit text in magit buffer when files are in Unstaged changes?

  • 3
    You can not edit text directly in the Magit buffer, but when your cursor is on the changes you want to edit you can press RET to jump to a buffer within Emacs in which you can edit the file. – Arnot Oct 6 '17 at 8:35
  • 2
  • 3
    "go to my editor (e.g. Notepad++)" ??!? – phils Oct 6 '17 at 11:48
  • 1
    @phils I hear it's not uncommon to use emacs just for magit; in fact, magit promotes the idea. – Sean Allred Oct 8 '17 at 17:37
  • 1
    @SeanAllred Indeed, but there's no denying at least a bit of irony. :) – Basil Oct 8 '17 at 18:52

The status buffer is just an interface to git; it's not an editor in itself, so you can't edit right from there. In Emacs, this isn't a problem, since you just RET and it takes you to the file/line/column you were at. There is still a feature request for this enhancement, but such functionality would be weird IMO since you'd have to enter some other mode within magit-status-mode since most keys already mean something special.

You mention though that you want to use a different editor to edit this text. If that is your real question, read below.

If your editor supports command-line arguments, you can do this rather easily at a file-level by advising magit-diff-visit-file:

(defun open-in-vscode (orig-fun &rest args)
  (let ((file (car args)))
    ;; If you don't want this behavior for every file/project,
    ;; you can still keep the old behavior using `orig-fun`.
    (if (or t (should-open-in-vs-code file))
         ;; This is VS Code, the only other editor I have installed
         ;; Look up Notepadd++'s arguments as appropriate.
         "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
         nil nil nil
      (apply orig-fun args))))

(advice-add #'magit-diff-visit-file :around #'open-in-vscode)

If you want to jump to the file:line:column, you'll have to dig deeper into magit-diff-visit-file and possibly provide a reimplementation (then advising using :override) that will do the right thing for you. The line/column information is already available in magit-diff-visit-file, so it would just be a matter of putting that information to other use.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.