branch: externals/beardbolt
commit 67238e02721f417662e48b967a7122488f6047ec
Author: Jay Kamat <[email protected]>
Commit: Jay Kamat <[email protected]>
Add rmsbolt-default-directory customization
Issue #10
Issue #4
---
README.org | 3 +++
rmsbolt.el | 30 ++++++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/README.org b/README.org
index 877befcc23..4a9dde26cc 100644
--- a/README.org
+++ b/README.org
@@ -82,6 +82,7 @@ Notable options:
| Option | Description
|
|-------------------------------+-------------------------------------------------------------------------------------------------------------------------------|
| ~rmsbolt-command~ | determines the prefix of the compilation
command to use. Use this to switch between compilers or pass flags to your
compiler. |
+| ~rmsbolt-default-directory~ | determines the default-drectory to compile
from.
|
| ~rmsbolt-disassemble~ | disassemble from a compiled binary with
objdump, if supported.
|
| ~rmsbolt-filter-*~ | Tweak filtering of binary output
|
| ~rmsbolt-intel-x86~ | Toggle between intel and att syntax if
supported
|
@@ -167,6 +168,8 @@ available in the compiled form if they exist.
- The compile-cmd-function is a function that will turn local variable
settings into a valid command which will take in a filename and output
assembly or an executable. See ~rmsbolt--c-compile-cmd~ for an example.
+ - When building compilation commands, please make sure to use absolute
paths,
+ as the default-directory is not guaranteed to be stable.
- If the assembly is not in a standard format, you will need to define a
~process-asm-custom-fn~ as well (see python/java for examples).
- If you would like to add language tweaks in your own config (ie: take full
diff --git a/rmsbolt.el b/rmsbolt.el
index e5b399fa8d..adc8cc78b0 100644
--- a/rmsbolt.el
+++ b/rmsbolt.el
@@ -45,10 +45,11 @@
;; change compiler and rmsbolt options simply by editing a local variable
block.
;;
;; Notable options:
-;; `rmsbolt-command': determines the prefix of the compilation command to use
+;; `rmsbolt-command': determines the prefix of the compilation command to use.
+;; `rmsbolt-default-directory': determines the default-drectory to compile
from.
;; `rmsbolt-disassemble': disassemble from a compiled binary with objdump, if
supported.
-;; `rmsbolt-filter-*': Tweak filtering of binary output
-;; `rmsbolt-intel-x86': Toggle between intel and att syntax if supported
+;; `rmsbolt-filter-*': Tweak filtering of binary output.
+;; `rmsbolt-intel-x86': Toggle between intel and att syntax if supported.
;; `rmsbolt-demangle': Demangle the output, if supported.
;;
;; Please see the readme at https://gitlab.com/jgkamat/rmsbolt for
@@ -112,6 +113,14 @@ This setting is automatically disabled on large buffers,
use
;; nil means use default command
:safe (lambda (v) (or (booleanp v) (stringp v)))
:group 'rmsbolt)
+(defcustom rmsbolt-default-directory nil
+ "The default directory to compile from.
+This must be an absolute path if set.
+Some exporters (such as pony) may not work with this set."
+ :type 'string
+ ;; nil means use default command
+ :safe (lambda (v) (or (booleanp v) (stringp v)))
+ :group 'rmsbolt)
(defcustom rmsbolt-intel-x86 t
"Whether to use intel x86 format or att."
:type 'boolean
@@ -297,6 +306,11 @@ This function does NOT quote the return value for use in
inferior shells."
:type 'string
:documentation "Default compilation command to use if none is provided.
If provided a function, call that function with the source buffer to determine
the compile command.")
+ (default-directory
+ nil
+ :type 'string
+ :documentation "Default directory to run compilation in. By default, use
rmsbolt--temp-dir.
+If provided a function, call that function with the source buffer to determine
the default directory.")
(compile-cmd-function
nil
:type 'function
@@ -1032,6 +1046,7 @@ Argument OVERRIDE-BUFFER use this buffer instead of
reading from the output file
(let* ((lang (rmsbolt--get-lang))
(src-buffer (current-buffer))
(cmd rmsbolt-command)
+ (dir rmsbolt-default-directory)
(force-disass (not (rmsbolt-l-supports-asm lang)))
(force-asm (not (rmsbolt-l-supports-disass lang))))
(when (and force-disass force-asm)
@@ -1040,6 +1055,12 @@ Argument OVERRIDE-BUFFER use this buffer instead of
reading from the output file
(setq-local rmsbolt-disassemble t))
(when force-asm
(setq-local rmsbolt-disassemble nil))
+ (when (not dir)
+ (setq-local rmsbolt-default-directory
+ (let ((new-dir (rmsbolt-l-default-directory lang)))
+ (pcase new-dir
+ ((pred functionp) (funcall new-dir src-buffer))
+ (_ new-dir)))))
(when (not cmd)
(setq-local rmsbolt-command
(let ((new-cmd (rmsbolt-l-compile-cmd lang)))
@@ -1089,7 +1110,8 @@ Argument OVERRIDE-BUFFER use this buffer instead of
reading from the output file
;; Generate command
(cmd (funcall func :src-buffer src-buffer))
- (default-directory rmsbolt--temp-dir))
+ (default-directory (or rmsbolt-default-directory
+ rmsbolt--temp-dir)))
(when (buffer-local-value 'rmsbolt-disassemble src-buffer)
(pcase
(rmsbolt-l-objdumper lang)