Skip to content

Stylish-haskell runs on buffer instead of file on disk #1266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -806,47 +806,33 @@ inferior GHCi process."
Use buffer as input and replace the whole buffer with the
output. If CMD fails the buffer remains unchanged."
(set-buffer-modified-p t)
(let* ((chomp (lambda (str)
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" str)
(setq str (replace-match "" t t str)))
str))
(_errout (lambda (fmt &rest args)
(let* ((warning-fill-prefix " "))
(display-warning cmd (apply 'format fmt args) :warning))))
(filename (buffer-file-name (current-buffer)))
(cmd-prefix (replace-regexp-in-string " .*" "" cmd))
(tmp-file (make-temp-file cmd-prefix))
(err-file (make-temp-file cmd-prefix))
(let* ((cmd-prefix (replace-regexp-in-string " .*" "" cmd))
(tmp-buf (generate-new-buffer cmd-prefix))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This temp buffer can be the same buffer as the one created with with-temp-buffer below, I think.

(default-directory (if (and (boundp 'haskell-session)
haskell-session)
(haskell-session-cabal-dir haskell-session)
default-directory))
(_errcode (with-temp-file tmp-file
(call-process cmd filename
(list (current-buffer) err-file) nil)))
(stderr-output
(with-temp-buffer
(insert-file-contents err-file)
(funcall chomp (buffer-substring-no-properties (point-min) (point-max)))))
(_errcode
(call-process-region (point-min) (point-max) cmd nil tmp-buf nil))
(stdout-output
(with-temp-buffer
(insert-file-contents tmp-file)
(insert-buffer tmp-buf)
(buffer-substring-no-properties (point-min) (point-max)))))
(if (string= "" stderr-output)
(if (zerop _errcode)
(if (string= "" stdout-output)
(message "Error: %s produced no output, leaving buffer alone" cmd)
(save-restriction
(widen)
;; command successful, insert file with replacement to preserve
;; markers.
(insert-file-contents tmp-file nil nil nil t)))
(erase-buffer)
(insert-buffer tmp-buf)))
(progn
;; non-null stderr, command must have failed
(message "Error: %s ended with errors, leaving buffer alone" cmd)
;; use (warning-minimum-level :debug) to see this
(display-warning cmd stderr-output :debug)))
(delete-file tmp-file)
(delete-file err-file)))
(kill-buffer tmp-buf)))

;;;###autoload
(defun haskell-mode-find-uses ()
Expand Down