Skip to content

Commit

Permalink
Improved integration with emacs.
Browse files Browse the repository at this point in the history
  • Loading branch information
fstromback committed Jan 22, 2016
1 parent 26a0c6e commit 9a3f511
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
12 changes: 6 additions & 6 deletions mm-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
;; when executing mymake. If 'buildconfig' was found, its contents (except any commented
;; lines, using #) are used as a parameter to mymake.
;; If the 'buildconfig'-file is not found, emacs starts mymake in the buffer's directory,
;; using the current buffer name as an input if it exists. This is to make it super-simple
;; using the current buffer name as a last-resort input. This is to make it super-simple
;; to start compiling using mymake; create a .cpp-file, write some code and hit M-p.
;; If you configure mymake to compile what you want automatically, create an empty 'buildconfig'-
;; file and emacs will not add any parameters.
;; If you are annoyed by this, set 'mymake-no-default-input' to 't'.
;; To force a recompile, you can prefix any mymake-command with C-u.
;; Release: C-c C-r. This will run mymake with 'release' as parameter.
;; Clean: C-c C-m.
Expand All @@ -22,6 +21,7 @@
(defvar mymake-compilation-w 100 "Compilation window width")
(defvar mymake-compilation-h 83 "Compilation window height")
(defvar mymake-compilation-adjust 10 "Compilation window adjustment")
(defvar mymake-no-default-input nil "Do not try to compile the current buffer if no buildconfig file is found.")

;; Keybindings
(global-set-key (kbd "M-p") 'mymake-compile)
Expand Down Expand Up @@ -59,7 +59,7 @@
(interactive "P")
(mymake-run :force force :replace "release 64"))

(defvar mymake-last-command "" "Last command used in 'mymake-command'.")
(defvar mymake-last-command "" "Last command used in the function 'mymake-command'.")

(defun mymake-command (command)
"Run custom mymake command."
Expand Down Expand Up @@ -134,9 +134,9 @@
;; No config file, we probably want to add the buffer file name as well.
(list
buffer-dir
(if (endp (buffer-file-name))
(if (or mymake-no-default-input (endp (buffer-file-name)))
""
(file-name-nondirectory (buffer-file-name))))
(concat "--default-input " (file-name-nondirectory (buffer-file-name)))))
(list
dir
(mymake-load-config-file (concat dir "buildconfig"))))))
Expand Down
15 changes: 14 additions & 1 deletion src/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static const pair<String, char> rawLongOptions[] = {
make_pair("project", '\3'),
make_pair("target", '\2'),
make_pair("config", '\1'),
make_pair("default-input", '\4'),
make_pair("help", '?'),
make_pair("threads", 'j'),
};
Expand All @@ -45,7 +46,9 @@ static const char *helpStr =
"--project - generate a sample .myproject in cwd.\n"
"--target - generate a sample .mymake in cwd.\n"
"--config - write global config file.\n"
"--threads, -j - compile in parallel if possible, using this many threads.\n";
"--threads, -j - compile in parallel if possible, using this many threads.\n"
"--default-input - add this file as an input if no other is specified on command-line\n"
" or in configuration. Useful when integrating with text editors.\n";

CmdLine::CmdLine(const vector<String> &params) :
errors(false),
Expand Down Expand Up @@ -243,6 +246,9 @@ bool CmdLine::parseOption(char opt) {
errors = true;
exit = true;
break;
case '\4':
state = sDefaultInput;
break;
default:
return false;
}
Expand Down Expand Up @@ -271,6 +277,9 @@ bool CmdLine::optionParam(const String &v) {
case sParallel:
threads = to<int>(v);
return true;
case sDefaultInput:
defaultInput = v;
return true;
default:
return false;
}
Expand All @@ -295,6 +304,10 @@ void CmdLine::apply(const set<String> &options, Config &config) const {
}
}

if (config.getArray("input").empty()) {
config.add("input", toS(Path(defaultInput).makeAbsolute()));
}

if (execute == tYes)
config.set("execute", "yes");
if (execute == tNo)
Expand Down
4 changes: 4 additions & 0 deletions src/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CmdLine : NoCopy {
sDebug,
sExecPath,
sParallel,
sDefaultInput,
};

State state;
Expand All @@ -76,6 +77,9 @@ class CmdLine : NoCopy {
// Order of the files/options.
vector<String> order;

// Add this file to input if none other exists. empty = do nothing.
String defaultInput;

// Number of threads to use. 0 = no opinion.
nat threads;

Expand Down

0 comments on commit 9a3f511

Please sign in to comment.