Last active
August 29, 2015 13:57
-
-
Save lateau/9394028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; gwan.el --- A G-WAN helper for Emacs 24 | |
;; Author: Daehyub Kim <lateau at gmail.com> | |
;; Version: 0.0 | |
;; Keywords: server, web, tool | |
;;; Commentary: | |
;; 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 GNU Emacs; see the file COPYING. If not, write to the | |
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
;; Boston, MA 02110-1301, USA. | |
;;; Code: | |
(defgroup gwan nil | |
"gwan" | |
:prefix "gwan-" | |
:group 'applications) | |
(defcustom gwan nil | |
"A path to excutable g-wan binary") | |
(defcustom gwan-gitignore "") | |
(defcustom gwan-download-url '(gnu/linux "http://gwan.com/archives/gwan_linux64-bit.tar.bz2") | |
"Download urls.") | |
(defcustom gwan-default-dirname '(gnu/linux "gwan_linux64-bit") | |
"A list of default directory names.") | |
(defconst gwan-command "gwan") | |
(defconst gwan-find-root-max-tries 100) | |
(defun gwan:find-root (&optional default count) | |
"Find and return current g-wan project root path. | |
This assumes that g-wan project root path should has 'gwan' the executable binary file." | |
(let* ((default-directory (or default default-directory)) | |
(count (or count 0)) | |
(gwan-path (locate-dominating-file default-directory gwan-command))) | |
(if gwan-path | |
(if (file-directory-p (format "%s/%s" gwan-path gwan-command)) | |
(and (> gwan-find-root-max-tries count) (gwan:find-root gwan-path (+ count 1))) | |
gwan-path)))) | |
(defun gwan:create () | |
"Create a new gwan project in current path." | |
(interactive) | |
(when (y-or-n-p "This could take several minutes. Proceed?") | |
(let* ((url (plist-get gwan-download-url system-type)) | |
(filename (file-name-nondirectory url)) | |
(input-project-name (completing-read "Project Name: " '())) | |
(project-name (or (and (string-equal "" input-project-name) "my_gwan") input-project-name))) | |
(url-copy-file url filename t) | |
(shell-command (format "tar xvjf %s" filename)) | |
(rename-file (plist-get gwan-default-dirname system-type) project-name)))) | |
(defun gwan:server () | |
"Start server." | |
(interactive) | |
(let ((project-root (gwan:find-root)) | |
(gwan (or gwan (format "./%s" gwan-command)))) | |
(when project-root | |
(cd project-root) | |
(start-process-shell-command "*gwan-server*" "*gwan-server*" "./gwan" nil) | |
(message "started")))) | |
;;;###autoload | |
(provide 'gwan) | |
;;; gwan.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment