[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beardbolt 4a6f289c94 002/323: Add very basic compilatio
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beardbolt 4a6f289c94 002/323: Add very basic compilation of c files |
Date: |
Thu, 9 Mar 2023 10:57:47 -0500 (EST) |
branch: externals/beardbolt
commit 4a6f289c9426f9f0a2f7ef8b3ed27084838ac58b
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>
Add very basic compilation of c files
---
rmsbolt.el | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 115 insertions(+), 2 deletions(-)
diff --git a/rmsbolt.el b/rmsbolt.el
index 65a441d8fd..62e418fccb 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -5,7 +5,7 @@
;; Version: 0.0.1
;; Keywords: compilation
;; URL: http://gitlab.com/jgkamat/rmsbolt
-;; Package-Requires: ((emacs "24.0"))
+;; Package-Requires: ((emacs "25.0"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -25,16 +25,129 @@
;;; Constants:
+(defconst +rmsbolt-compile-name+ "rmsbolt-compile")
;;; Code:
;;;; Variables:
+(defvar rmsbolt-temp-dir nil
+ "Temporary directory to use for compilation and other reasons.")
+(defvar rmsbolt-shell "bash"
+ "Shell rmsbolt will use to split paths.")
+(defvar rmsbolt-output-buffer "*rmsbolt-output*")
+(defvar rmsbolt-output-filename "rmsbolt.s")
+(defvar rmsbolt-hide-compile t)
+
+;;;; Macros
+
+(defmacro rmsbolt-with-display-buffer-no-window (&rest body)
+ ;; See http://debbugs.gnu.org/13594
+ `(let ((display-buffer-overriding-action
+ (if rmsbolt-hide-compile
+ (list #'display-buffer-no-window)
+ display-buffer-overriding-action)))
+ ,@body))
+
+
+;;;; Functions
+(defun rmsbolt--handle-finish-compile (buffer _str)
+ "Finish hook for compilations."
+ (let ((compilation-fail
+ (with-current-buffer buffer
+ (eq 'compilation-mode-line-fail
+ (get-text-property 0 'face (car mode-line-process)))))
+ (default-directory (buffer-local-value 'default-directory buffer)))
+
+ (with-current-buffer (get-buffer-create rmsbolt-output-buffer)
+ (cond ((not compilation-fail)
+ (delete-region (point-min) (point-max))
+ (insert-file-contents rmsbolt-output-filename)
+ (asm-mode)
+ (display-buffer (current-buffer)))
+ (t
+ ;; Display compilation output
+ (display-buffer buffer))))))
+
+(defun rmsbolt-compile ()
+ "Compile the current rmsbolt buffer."
+ (interactive)
+ (save-some-buffers nil (lambda () rmsbolt-mode))
+ (let* ((cmd "gcc -O0")
+ (cmd (mapconcat 'identity
+ (list cmd
+ "-S" (buffer-file-name)
+ "-o" rmsbolt-output-filename)
+ " ")))
+ (rmsbolt-with-display-buffer-no-window
+ (with-current-buffer (compilation-start cmd)
+ (add-hook 'compilation-finish-functions
+ #'rmsbolt--handle-finish-compile nil t))))
+
+ ;; TODO
+ )
+
+;;;; Alda Keymap
+(defvar rmsbolt-mode-map nil "Keymap for `alda-mode'.")
+(when (not rmsbolt-mode-map) ; if it is not already defined
+
+ ;; assign command to keys
+ (setq rmsbolt-mode-map (make-sparse-keymap))
+ (define-key rmsbolt-mode-map (kbd "C-c C-c") #'rmsbolt-compile))
+
+;;;; Init commands
+
+(defun rmsbolt-c ()
+ (interactive)
+ (let* ((file-name (expand-file-name "rmsbolt.c" rmsbolt-temp-dir))
+ (exists (file-exists-p file-name)))
+ (find-file file-name)
+ (unless exists
+ (insert
+ "#include <stdio.h>
+
+// RMS: gcc -O0
+
+int isRMS(int a) {
+ switch (a) {
+ case 'R':
+ return 1;
+ case 'M':
+ return 2;
+ case 'S':
+ return 3;
+ default:
+ return 0;
+ }
+}
+
+int main() {
+ char a = 1 + 1;
+ if (isRMS(a))
+ printf(\"%c\\n\", a);
+}
+")
+ (save-buffer))
+
+ (unless rmsbolt-mode
+ (rmsbolt-mode 1))
+ )
+ )
;;;; Mode Definition:
;;;###autoload
-(define-derived-mode rmsbolt-mode c-mode
+;; TODO handle more modes than c-mode
+(define-minor-mode rmsbolt-mode
"RMSbolt"
+ nil "RMSBolt" rmsbolt-mode-map
+ (unless rmsbolt-temp-dir
+ (setq rmsbolt-temp-dir
+ (make-temp-file "rmsbolt-" t))
+ (add-hook 'kill-emacs-hook
+ (lambda ()
+ (delete-directory rmsbolt-temp-dir t)
+ (setq rmsbolt-temp-dir nil))))
+
)
(provide 'rmsbolt)
- [elpa] externals/beardbolt 730ea84796 290/323: bb-compile-delay can be nil, (continued)
- [elpa] externals/beardbolt 730ea84796 290/323: bb-compile-delay can be nil, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 2c798336b8 292/323: Tweak README.md, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt c05a0be490 297/323: Add useful beardbolt-preserve-library-functions, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 26c0b918e4 301/323: Tweak README.md again, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e1e69080b7 303/323: Rename "output buffer" -> "asm buffer", ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt dbafc4a88c 304/323: Minor cleanup, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 68469cfb57 306/323: More misc minor rework to simplify code, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 02a0bfbcdb 313/323: Add `beardbolt-ccj-extra-flags` option, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 6a71a16619 319/323: Simplify rainbow-clearing logic, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e403331350 322/323: * beardbolt.el (bb--synch-relation-overlays): Fix bug., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4a6f289c94 002/323: Add very basic compilation of c files,
ELPA Syncer <=
- [elpa] externals/beardbolt ac893146e3 019/323: Force dissasembly if we don't support asm, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f30a05624d 051/323: Add support for parsing .file directives, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 865d5a8c1a 111/323: Clean up CI config, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 7f61815c17 121/323: Try to fix bytecode issues, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt e517cd4dbc 142/323: Remove unneeded disass-hidden-funcs overrides, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt f89875215b 128/323: Fix byte-compilation warnings, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt cb0b781e82 143/323: Add rudimentary support for hack/hhvm, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 4f86bae37e 144/323: Add rmsbolt-asm-format for toggling between asm formats., ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt 20fa6a76e0 150/323: Clear out unset or nil variables after setting them via defaults, ELPA Syncer, 2023/03/09
- [elpa] externals/beardbolt fc712fe954 147/323: Fix typo in readme, ELPA Syncer, 2023/03/09