Skip to content

Commit 8e874a8

Browse files
authored
Merge pull request #733 from emacs-php/feature/php-format-disable-async-format
Add php-format-disable-async-format-buffer-has-modified
2 parents e6e4ac5 + 7708392 commit 8e874a8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lisp/php-format.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
:type '(alist :key-type function
129129
:value-type symbol)
130130
:group 'php-format)
131+
132+
(defcustom php-format-disable-async-format-buffer-has-modified t
133+
"When non-NIL, disable asynchronous formatting if the buffer has modified (not saved)."
134+
:tag "PHP Format Disable Async Format Buffer Has Modified"
135+
:type 'boolean
136+
:group 'php-format)
131137

132138
;; Internal functions
133139
(defsubst php-format--register-timer (sec command-args)
@@ -182,8 +188,10 @@
182188
"Asynchronously execute PHP format with COMMAND-ARGS in DIR."
183189
(setq php-format--idle-timer nil)
184190
(let ((default-directory dir))
185-
(apply #'call-process-shell-command (car command-args) nil nil nil
186-
(append (cdr command-args) (list "&")))))
191+
(when (not (and php-format-disable-async-format-buffer-has-modified
192+
(buffer-modified-p)))
193+
(apply #'call-process-shell-command (car command-args) nil nil nil
194+
(append (cdr command-args) (list "&"))))))
187195

188196
;; Public functions and minor mode
189197

0 commit comments

Comments
 (0)