From 2b4cd50b240aa3aaafbbfe2bd79f8e9a55218f4f Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Thu, 12 Jan 2023 10:20:33 -0600 Subject: [PATCH] Can now kill cc1 command from compilation buffer --- lisp/llvm-lib/llvm-gdb-command.el | 72 +++++++++++++++++-------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/lisp/llvm-lib/llvm-gdb-command.el b/lisp/llvm-lib/llvm-gdb-command.el index 11746cb..32d5bd0 100644 --- a/lisp/llvm-lib/llvm-gdb-command.el +++ b/lisp/llvm-lib/llvm-gdb-command.el @@ -28,42 +28,48 @@ (require 'llvm-shared) (require 'anaphora) -(defun ll/get-cc1-command (file) - (let* ((fname (file-name-nondirectory file)) - (buffer (format "*cc1-%s*" fname)) - (clang (lls/prompt-tool "clang$"))) - (save-window-excursion - (let ((command (string-join - (list (funcall - lls/get-clang-command-fun - clang file 'compile - :output (make-temp-file nil nil ".o")) - "-v") - " "))) - (while - (progn - (shell-command command buffer) - (aprog1 (ll/buffer-has-include-error buffer) - (when it - (setq command - (ll/add-include-folder-to-command command))))))) - (with-current-buffer (get-buffer buffer) - (beginning-of-buffer) - (re-search-forward (rx "\"" (literal clang) "\" " - (group "-cc1" (+ nonl)))) - (match-string 1))))) +(defun ll/get-cc1-command (clang command) + (let ((buffer (get-buffer-create "*cc1*"))) + (while + (progn + (shell-command command buffer) + (aprog1 (ll/buffer-has-include-error buffer) + (when it + (setq command + (ll/add-include-folder-to-command command)))))) + (with-current-buffer (get-buffer buffer) + (beginning-of-buffer) + (re-search-forward (rx "\"" (literal clang) "\" " + (group "-cc1" (+ nonl)))) + (match-string 1)))) -(defun ll/kill-gdb-command (file) - (interactive - (list - (or (let ((fname (buffer-file-name (current-buffer)))) - (and (string= "c" (file-name-extension fname)) - fname)) - (read-file-name "Which file? ")))) - (let ((fname (file-name-nondirectory file))) +(defun ll/get-clang-command-for-file (clang file) + (string-join + (list (funcall + lls/get-clang-command-fun + clang file 'compile + :output (make-temp-file nil nil ".o")) + "-v") + " ")) + +(defun ll/kill-gdb-command () + (interactive) + (let* ((buf (current-buffer)) + (fname (buffer-file-name buf)) + (clang (lls/prompt-tool "clang$")) + (command + (with-current-buffer buf + (cond ((or compilation-minor-mode + (eq major-mode 'compilation-mode)) + (concat (car compilation-arguments) " -v")) + ((string= "c" (file-name-extension fname)) + (ll/get-clang-command-for-file clang fname)) + (t + (ll/get-clang-command-for-file clang + (read-file-name "File? "))))))) (kill-new (format "r %s" - (ll/get-cc1-command file))))) + (ll/get-cc1-command clang command))))) (provide 'llvm-gdb-command) ;;; llvm-gdb-command.el ends here