0

I am having difficulties ignoring the stderr stream of my call to LuaFormatter from Emacs (see call-shell-region):

(defun rpo-lua-format-buffer ()
  (let ((formatter-cfg-file ".lua-format")
        (formatter-cfg-dir  (locate-dominating-file "." ".lua-format")))
    (if formatter-cfg-dir
        (let* (tmp-buffer-name (make-temp-name "tmp")
                               (tmp-buffer (get-buffer-create tmp-buffer-name)))
          (if (eq 0 (call-shell-region
                     (point-min) (point-max) (concat "lua-format --config=" (expand-file-name (concat formatter-cfg-dir formatter-cfg-file))) nil '(tmp-buffer nil)))
              (replace-buffer-contents tmp-buffer 3)
            (error "lua-format failed."))
          (kill-buffer tmp-buffer))
      #'er-indent-and-cleanup-region-or-buffer)))

The error I get, when calling this function (from a before-save-hook) is:

Error: (wrong-type-argument stringp nil)

However, when I replace the last argument '(tmp-buffer nil) of shell-call-region with tmp-buffer alone, I get stdout and stderr merged in the new buffer.

How can I get rid of the stream content of stderr and only keep stdout?

1 Answer 1

3

Your list is quoted, so you are passing in a list with two symbols rather than a buffer and nil. Use list rather than quote:

(call-shell-region (point-min) (point-max)
                   (concat "lua-format --config="
                           (expand-file-name (concat formatter-cfg-dir
                                                     formatter-cfg-file)))
                   nil
                   (list tmp-buffer nil))
2
  • Thanks for your quick help! That solved it. I should definitely learn more about the basics - data types in this case.
    – dubbaluga
    Jan 18 at 12:33
  • 1
    @dubbaluga It's important to understand that '... which means (quote ...) is not a shorthand for making lists. It's a form which causes lisp to return, unevaluated, the object that was created by the lisp reader. Be sure to go over the distinct read and eval phases of lisp execution. Once you understand the distinction, quote will make much more sense (and you'll be able to avoid related confusions such as inadvertent self-modifying code).
    – phils
    Jan 18 at 21:12

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.