Skip to content
Browse files

Merge branch 'change-default'

  • Loading branch information...
2 parents a4f5d1d + fe1b9fb commit 90ed7a9667035e4ec0fb072c8346d71458a7f559 @syohex committed
Showing with 95 additions and 8 deletions.
  1. +4 −0 Makefile
  2. +9 −3 example/quickrun_conf.el
  3. +17 −5 quickrun.el
  4. +65 −0 test-quickrun.el
View
4 Makefile
@@ -0,0 +1,4 @@
+.PHONY : test
+
+test:
+ emacs -Q -batch -L . -l test-quickrun.el -f ert-run-tests-batch-and-exit
View
12 example/quickrun_conf.el
@@ -16,11 +16,17 @@
;; Add C++ command for C11 and set it default in C++ file.
(quickrun-add-command "c++/c11"
'((:command . "g++")
- (:exec . ("%c -std=c++0x %o -o %n %s"
- "%n %a"))
- (:remove . ("%n")))
+ (:exec . ("%c -std=c++0x %o -o %e %s"
+ "%e %a"))
+ (:remove . ("%e")))
:default "c++")
+;; Override existed command
+(quickrun-add-command "c/gcc"
+ '((:exec . ("%c -std=c++0x %e -o %e %s"
+ "%e %a")))
+ :override t)
+
;; Add pod command and set to use when extension of file is '.pod'
;; or major-mode of file is pod-mode.
(quickrun-add-command "pod"
View
22 quickrun.el
@@ -785,13 +785,25 @@ by quickrun.el. But you can register your own command for some languages")
(error "%s is not registered." key))
(puthash lang key quickrun/command-key-table))
+(defun quickrun/override-command (cmdkey cmd-alist)
+ (let ((registerd (assoc-default cmdkey quickrun/language-alist)))
+ (unless registerd
+ (error (message "'%s' is not registerd" cmdkey)))
+ (loop for old-param in registerd
+ do
+ (let ((new-value (assoc-default (car old-param) cmd-alist)))
+ (if new-value
+ (setcdr old-param new-value))))))
+
;;;###autoload
-(defun* quickrun-add-command (key alist &key default mode)
+(defun* quickrun-add-command (key alist &key default mode override)
(cond ((not key) (error "undefined 1st argument 'key'"))
- ((not alist) (error "undefined 2nd argument 'command alist'"))
- ((not (assoc :command alist))
- (error "not found :command parameter in language alist")))
- (push (cons key (copy-alist alist)) quickrun/language-alist)
+ ((not alist) (error "undefined 2nd argument 'command alist'")))
+ (if override
+ (quickrun/override-command key (copy-alist alist))
+ (if (not (assoc :command alist))
+ (error "not found :command parameter in language alist")
+ (push (cons key (copy-alist alist)) quickrun/language-alist)))
(let ((cmd-key (or default key)))
(if default
(puthash cmd-key key quickrun/command-key-table))
View
65 test-quickrun.el
@@ -0,0 +1,65 @@
+;;; test-quickrun.el ---
+
+;; Copyright (C) 2012 by Syohei YOSHIDA
+
+;; Author: Syohei YOSHIDA <syohex@gmail.com>
+;; URL:
+;; Version: 0.01
+
+;; 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
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(eval-when-compile
+ (require 'cl))
+
+(require 'ert)
+(require 'quickrun)
+
+(ert-deftest quickrun:exec-quickrun ()
+ "Exec `quickrun'"
+ (let ((buf (find-file-noselect "sample/sample.py")))
+ (with-current-buffer buf
+ (quickrun))
+ ;; quickrun is async function
+ (sleep-for 1)
+ (with-current-buffer "*quickrun*"
+ (let ((str (buffer-substring-no-properties (point-min) (point-max))))
+ (should (string= "Hello Python quickrun.el\n" str))))))
+
+(ert-deftest quickrun:add-command ()
+ "Add new command"
+ (quickrun-add-command "-test"
+ '((:command . "test foo")
+ (:description . "test description")))
+ (let ((params (assoc-default "-test" quickrun/language-alist)))
+ (should params)
+ (let ((command (assoc-default :command params))
+ (desc (assoc-default :description params)))
+ (should (string= command "test foo"))
+ (should (string= desc "test description")))))
+
+(ert-deftest quickrun:override-configuration ()
+ "Override registerd command"
+ (quickrun-add-command "c/gcc"
+ '((:command . "clang")
+ (:description . "Compile clang"))
+ :override t)
+ (let* ((params (assoc-default "c/gcc" quickrun/language-alist))
+ (command (assoc-default :command params)))
+ (should (string= command "clang"))))
+
+;;; test-quickrun.el ends here

0 comments on commit 90ed7a9

Please sign in to comment.
Something went wrong with that request. Please try again.