diff options
| author | Steve Lee <me@xiangyangli.com> | 2017-12-15 07:36:33 +0800 |
|---|---|---|
| committer | Steve Lee <me@xiangyangli.com> | 2017-12-15 07:36:33 +0800 |
| commit | 8dd747b1db2b7f51a5077ceefcbbb76203c5bc05 (patch) | |
| tree | 77b8c475f28b89f5dde89fc23f6068b288bc2bea /.emacs.d/lisp/init-program-basic.el~ | |
| parent | dbff7cfe3fae6418bd37d897c6b3703d3ccf87cf (diff) | |
| download | dotfiles-8dd747b1db2b7f51a5077ceefcbbb76203c5bc05.tar.xz dotfiles-8dd747b1db2b7f51a5077ceefcbbb76203c5bc05.zip | |
update
Diffstat (limited to '.emacs.d/lisp/init-program-basic.el~')
| -rw-r--r-- | .emacs.d/lisp/init-program-basic.el~ | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/.emacs.d/lisp/init-program-basic.el~ b/.emacs.d/lisp/init-program-basic.el~ index 2e68074..1e852ad 100644 --- a/.emacs.d/lisp/init-program-basic.el~ +++ b/.emacs.d/lisp/init-program-basic.el~ @@ -1,13 +1,52 @@ -;; C programming +;;; program-basic --- Some basic configuration + +;;; Commentary: +;; None + +;;; Code: + (setq-default c-basic-offset 4 tab-width 4 indent-tabs-mode t) (defun execute-c-program () + "Complie current c file and run it." (interactive) (defvar foo) (setq foo (concat - "gcc " (buffer-name) " -o " (buffer-name) ".out && ./" (buffer-name) ".out" )) + "gcc " (include-source-file (buffer-name)) " -o " (buffer-name) ".out && ./" (buffer-name) ".out" )) (shell-command foo)) +(defun include-source-file (file-path) + "Get transfer all include header file from FILE-PATH to source file(string)." + (let (content) + (setq content (format "%s" (get-c-source-file (get-string-from-file file-path)))) + (if (string= nil content) + file-path + (substring content 1 -1)))) + +(defun get-c-source-file (content) + "Get the header list of a string CONTENT, for instant a .c file." + (defun header-to-source (header) + "Whole line of header" + (replace-regexp-in-string "[.]h" ".c " (substring header 10 -1))) + (let (value) + (dolist (element (split-string content "\n" t) value) + (if (string-prefix-p "#include \"" element) + (setq value (cons (header-to-source element) value)))))) + + +(defun read-lines (file-path) + "Return a list of lines of a file at FILE-PATH." + (with-temp-buffer + (insert-file-contents file-path) + (split-string (buffer-string) "\n" t))) + +(defun get-string-from-file (file-path) + "Return FILE-PATH's file content in list." + (with-temp-buffer + (insert-file-contents file-path) + (buffer-string))) + (provide 'init-program-basic) +;;; init-program-basic ends here |
