2011-01-03 06:00:56 +00:00
|
|
|
;; Kuso - My personal emacs IDE
|
2010-12-25 13:49:03 +00:00
|
|
|
;; Copyright (C) 2010 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
;;
|
|
|
|
;; 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
|
|
|
|
;; 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/>.
|
|
|
|
|
2011-01-03 06:00:56 +00:00
|
|
|
;; C project plugin for Kuso IDE
|
2010-12-25 13:49:03 +00:00
|
|
|
|
2011-01-02 17:06:13 +00:00
|
|
|
;; ---------------------------------------------------------------------
|
|
|
|
;; Groups
|
|
|
|
;; ---------------------------------------------------------------------
|
2011-01-03 06:00:56 +00:00
|
|
|
(defgroup kuso-cplugin nil
|
|
|
|
"This group contains all the optional components of Kuso IDE C plugin."
|
2011-01-03 07:58:02 +00:00
|
|
|
:group 'kuso-ide
|
2011-01-02 17:06:13 +00:00
|
|
|
)
|
|
|
|
|
2011-01-02 17:53:23 +00:00
|
|
|
;; ---------------------------------------------------------------------
|
|
|
|
;; Custom Variables
|
|
|
|
;; ---------------------------------------------------------------------
|
|
|
|
(defcustom c-plugin t
|
2011-01-03 06:00:56 +00:00
|
|
|
"KusoIDE C programming language plugin."
|
|
|
|
:group 'kuso-features
|
2011-01-02 17:53:23 +00:00
|
|
|
:type 'boolean
|
|
|
|
:tag '"C Plugin")
|
|
|
|
|
2010-12-25 13:49:03 +00:00
|
|
|
|
2011-01-03 13:30:06 +00:00
|
|
|
;; ----------------------------------------------------------------------
|
|
|
|
;; Minor Mode Initialization
|
|
|
|
;; ----------------------------------------------------------------------
|
2010-12-29 18:19:43 +00:00
|
|
|
|
2011-01-03 13:30:06 +00:00
|
|
|
;; If user dont want the plug in so it should not loaded
|
2011-01-04 19:24:41 +00:00
|
|
|
;; -------------------------------------------------------------------
|
|
|
|
;; Hooks
|
|
|
|
;; -------------------------------------------------------------------
|
|
|
|
(defvar kuso-cplug-preinit-hook '()
|
|
|
|
"This hook runs before initializing the Kuso c-plugin minor mode."
|
|
|
|
)
|
2011-01-02 17:52:02 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
(defvar kuso-cplug-postinit-hook '()
|
|
|
|
"This hook runs after Kuso c-plugin minor mode initialized."
|
|
|
|
)
|
2011-01-03 07:34:43 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
(defvar kuso-cplug-prerm--hook '()
|
|
|
|
"This hook runs before deactivating Kuso c-plugin minor mode."
|
|
|
|
)
|
2011-01-03 13:30:06 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
(defvar kuso-cplug-postrm-hook '()
|
|
|
|
"This hook runs after Kuso c-plugin minor mode deactivated."
|
|
|
|
)
|
2011-01-03 13:30:06 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
;; ---------------------------------------------------------------------
|
|
|
|
;; Keymaps
|
|
|
|
;; ---------------------------------------------------------------------
|
|
|
|
(defvar kuso-cplugin-map (make-sparse-keymap)
|
|
|
|
"Default keymap for Kuso c-plugin minor mode that hold the global key
|
|
|
|
binding for Kuso IDE C projects section."
|
|
|
|
)
|
2011-01-03 13:30:06 +00:00
|
|
|
|
|
|
|
|
2010-12-29 18:19:43 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
;; ---------------------------------------------------------------------
|
|
|
|
;; Functions
|
|
|
|
;; ---------------------------------------------------------------------
|
2011-01-05 06:53:32 +00:00
|
|
|
(defun cplugin/init-menus () "Draw required menu for C mode"
|
2011-01-04 19:43:54 +00:00
|
|
|
|
2011-01-05 06:53:32 +00:00
|
|
|
(interactive)
|
2011-01-04 19:24:41 +00:00
|
|
|
(define-key-after global-map [menu-bar file new-proj cproj] (cons "C/C++" (make-sparse-keymap "c-cpp-proj")))
|
2011-01-05 06:53:32 +00:00
|
|
|
(log "B")
|
2011-01-04 19:24:41 +00:00
|
|
|
;; (define-key global-map (kbd "\C-x n k") 'kmodule)
|
|
|
|
;; (define-key global-map [menu-bar file new-proj cproj kmodule] '("Kernel Module" . kmodule))
|
|
|
|
|
|
|
|
;; (define-key global-map [menu-bar file new-proj cproj separator2] '("--"))
|
|
|
|
|
|
|
|
; (define-key global-map [Ctrl-x p c n ] 'make-cpp)
|
|
|
|
;; (define-key global-map [menu-bar file new-proj cproj cpp-make] '("Make project (C++)" . make-cpp))
|
|
|
|
|
|
|
|
;; (define-key global-map [Ctrl-x p c m ] 'make-c)
|
|
|
|
;; (define-key global-map [menu-bar file new-proj cproj c-make] '("Make project (C)" . make-c))
|
|
|
|
|
|
|
|
;; (define-key global-map [menu-bar file new-proj cproj separator1] '("--"))
|
|
|
|
|
|
|
|
(define-key global-map (kbd "\C-x n \C-c") 'generic-cpp)
|
|
|
|
(define-key global-map [menu-bar file new-proj cproj cppgeneric] '("Generic project (C++)" . generic-cpp))
|
|
|
|
|
|
|
|
(define-key global-map (kbd "\C-x n c") 'generic-c)
|
|
|
|
(define-key global-map [menu-bar file new-proj cproj cgeneric] '("Generic project (C)" . generic-c))
|
2011-01-05 06:53:32 +00:00
|
|
|
(log "C")
|
2011-01-04 19:24:41 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
;; Thsi function exists because maybe Kuso needs more information
|
|
|
|
;; about new project in the feature the new-prject function did not
|
|
|
|
;; cover
|
|
|
|
(defun c-new-project () "Create a new C/C++ project"
|
|
|
|
(new-project)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
(defun compile ()
|
|
|
|
"Run the make command and return the putput"
|
|
|
|
(interactive)
|
|
|
|
(let (output)
|
|
|
|
(setq output (shell-command-to-string "make"))
|
|
|
|
(message output)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(defun generic-c () "Create a generic type C project"
|
|
|
|
(interactive)
|
|
|
|
(c-new-project)
|
|
|
|
(project/copying-license-copy)
|
|
|
|
(let (template-file-regexp license-data filelist cur template-data)
|
|
|
|
(setq template-file-regexp (concat TEMPLATESPATH "c/generic_c/*.tmpl"))
|
|
|
|
(setq filelist (file-expand-wildcards template-file-regexp))
|
|
|
|
(while filelist
|
|
|
|
(setq cur (pop filelist))
|
|
|
|
(setq template-data (project/render-template cur))
|
|
|
|
(setq template-data (replace-regexp-in-string "::unixname::" unix-project-name template-data))
|
|
|
|
(setq template-data (replace-regexp-in-string "::UNIXNAME::" unix-project-name template-data))
|
|
|
|
(project/write-dest-file cur template-data)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(cd project-path)
|
|
|
|
(find-file (concat unix-project-name ".c"))
|
|
|
|
(kuso-cplugin-mode)
|
|
|
|
)
|
2011-01-03 13:30:06 +00:00
|
|
|
|
2011-01-05 06:53:32 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
(defun initial-keymap ()
|
|
|
|
"Set the key binding for C project."
|
|
|
|
(define-key kuso-cplugin-map (kbd "\C-c \C-c") 'compile)
|
|
|
|
)
|
2011-01-03 13:30:06 +00:00
|
|
|
|
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
;; Initializing c menus at the load time
|
2011-01-05 06:53:32 +00:00
|
|
|
(add-hook 'kuso-postinit-mode-hook 'cplugin/init-menus)
|
|
|
|
(add-hook 'kuso-plugin-init-hook 'kuso-cplugin-mode)
|
2011-01-06 15:16:17 +00:00
|
|
|
|
2011-01-04 19:24:41 +00:00
|
|
|
;; ----------------------------------------------------------------------
|
|
|
|
;; Minor Modes
|
|
|
|
;; ----------------------------------------------------------------------
|
|
|
|
(define-minor-mode kuso-cplugin-mode
|
|
|
|
"Toggle Kuso C plugin mode.
|
2011-01-03 13:30:06 +00:00
|
|
|
This mode provide C language plugin for Kuso IDE."
|
2011-01-04 19:24:41 +00:00
|
|
|
:lighter " kuso-c"
|
|
|
|
:keymap kuso-cplugin-map
|
|
|
|
:global t
|
|
|
|
:group 'kuso-group
|
|
|
|
|
|
|
|
(if kuso-cplugin-mode
|
|
|
|
;; kuso-cplugin-mode is not loaded
|
|
|
|
(let ()
|
2011-01-06 15:16:17 +00:00
|
|
|
(if c-plugin
|
|
|
|
(progn
|
|
|
|
;; before initiazing mode
|
|
|
|
(run-hooks 'kuso-cplug-preinit-hook)
|
|
|
|
(initial-keymap)
|
|
|
|
(log "Z")
|
|
|
|
;; after mode was initialized
|
|
|
|
(run-hooks 'kuso-cplug-postinit-hook)
|
|
|
|
)
|
|
|
|
(log "C Plugin turned off")
|
|
|
|
)
|
2011-01-03 13:30:06 +00:00
|
|
|
)
|
2011-01-04 19:24:41 +00:00
|
|
|
;; kuso-mode already loaded
|
|
|
|
(let ()
|
|
|
|
;; before deactivating mode
|
|
|
|
(run-hooks 'kuso-cplug-prerm-hook)
|
|
|
|
;; after deactivating mode
|
|
|
|
(run-hooks 'kuso-cplug-postrm-hook)
|
2011-01-03 13:34:58 +00:00
|
|
|
)
|
2011-01-04 19:24:41 +00:00
|
|
|
)
|
2011-01-03 13:34:58 +00:00
|
|
|
)
|