Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs ediff error "no newline at end of file"

On Debian Wheezy, Emacs 23.3.1, running ediff-files with a file that is missing a newline at the end results in the error \ No newline at end of file (I hope that's the correct translation; it's German \ Kein Zeilenumbruch am Dateiende. on my computer.)

Is it possible to have just a warning instead, so that I can see the diff and work on it (and fix the missing newline)? It's just a bit tedious to first have ediff fail, then open the file, add the newline, ediff again.

like image 690
Florian Jenn Avatar asked Jan 18 '23 12:01

Florian Jenn


1 Answers

Try changing the value of the variable ediff-diff-ok-lines-regexp to include the German text ("Kein Zeilenumbruch am Dateiende"):

(setq ediff-diff-ok-lines-regexp
      (concat
       "^\\("
       "[0-9,]+[acd][0-9,]+\C-m?$"
       "\\|[] "
       "\\|---"
       "\\|.*Warning *:"
       "\\|.*No +newline"
       "\\|.*missing +newline"
       "\\|.*Kein +Zeilenumbruch +am +Dateiende"
       "\\|^\C-m?$"
       "\\)"))

Update: Looking at the source code, it does seem that Ediff doesn't make any attempt to deal with the issue of localization of messages from diff. It should also be possible to work around this by wrapping diff in a shell script, e.g:

#!/bin/bash
LANG=C diff $*

..then customising the ediff-diff-program to call the wrapper instead:

(setq ediff-diff-program "~/bin/my-diff.sh")

Other code in the Emacs source directory lisp/vc does seem to handle this, for example vc-hg-state:

(defun vc-hg-state (file)
  "Hg-specific version of `vc-state'."
   ...
        (with-output-to-string
          (with-current-buffer
              standard-output
            (setq status
                  (condition-case nil
                      ;; Ignore all errors.
              (let ((process-environment
                 ;; Avoid localization of messages so we
                 ;; can parse the output.
                 (append (list "TERM=dumb" "LANGUAGE=C")
                     process-environment)))
   ...

It seems a bit strange that Ediff doesn't also do this, but perhaps I'm missing something.

like image 167
Luke Girvin Avatar answered Jan 28 '23 03:01

Luke Girvin