blob: 5bc89a9cc058639f614f9a2f1250659136d78987 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
;;; program-basic --- Some basic configuration
;;; Commentary:
;; None
;;; Code:
(setq-default c-basic-offset 4
tab-width 4
indent-tabs-mode t)
(defun execute-python-program ()
"Run current python script."
(interactive)
(save-buffer)
(defvar foo)
(setq foo (concat "python " (buffer-name)))
(shell-command foo))
(defun execute-c-program ()
"Complie current c file and run it."
(interactive)
(save-buffer)
(defvar foo)
(setq foo (concat
"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
|