.emacs 백업(Windows/Linux)

2014. 1. 2. 17:04

1. 윈도우즈용

윈도우즈에서는 .emacs파일이 생성되지 않지만 emacs에서 Save as(C-x C-w)를 통해 생성할 수 있다. mit-scheme연동이 되지 않기 때문에 scheme을 할 때는 그저 editor로만 사용할 셈이다.

C:\emacs에 emacs를 깔고(압축을 풀고) slime과 auto-complete도 넣은 뒤 paredit.el은 slime폴더에 넣었다.

c언어를 컴파일 할때는 소스창에서 f3을 누르고 엔터를 누르면 소스의 디렉토리에 test.exe형태로 컴파일 된다. 실행은 f4를 누르고 gdb를 이용해도 되고, 다른 버퍼에서 f12를 누르고 cmd shell을 이용해도 된다. 컴파일 할 때 -g로 하고 gdb실행할 때 -q추가하면 list로 소스를 볼 수 있고, 디버깅이 가능하다.

(display-time)

;;Windows specific setting
(global-set-key [C-kanji] 'set-mark-command)

;;autopair
(add-to-list 'load-path "C:/emacs/site-lisp")
(require 'autopair)

;;C/Cpp language
(setq c-basic-offset 8
      c-default-style "linux")
(mapc (lambda (mode)
        (let ((hook (intern (concat (symbol-name mode)    
                                    "-mode-hook"))))    
          (add-hook hook (lambda ()
			   (local-set-key (kbd "RET") 'newline-and-indent)
			   (autopair-mode 1)))))
      '(c c++))
(add-hook 'c-mode-hook
	  (lambda ()
	    (set (make-local-variable 'compile-command)
		 (let ((file (file-name-nondirectory buffer-file-name)))
		   (format "%s %s.c -o %s -g"
			   "gcc"
			   (file-name-sans-extension file)
			   "test")))))
(add-hook 'c++-mode-hook
	  (lambda ()
	    (set (make-local-variable 'compile-command)
		 (let ((file (file-name-nondirectory buffer-file-name)))
		   (format "%s %s.cpp -o %s -g"
			   "g++"
			   (file-name-sans-extension file)
			   "test")))))

;;#slime setting
(add-to-list 'load-path "C:/emacs/slime")
(require 'slime)
(slime-setup '(slime-repl))
 
;;#paredit setting
(autoload 'paredit-mode "paredit"   
  "minor mode for pseudo-structurally editing Lisp code." t)
 
(add-hook 'scheme-mode-hook (lambda () (slime-mode 1)))

;;slime-repl-mode lisp-indent-fuction
(add-hook 'slime-repl-mode-hook
          (defun slime-repl-indent-hook ()
            (set (make-local-variable 'lisp-indent-function)
                 'scheme-indent-function)))
 
;;skip startup screen and make scheme as major mode
(setq initial-major-mode 'scheme-mode)
(setq inhibit-startup-screen t)
(global-linum-mode t)
 
 
 
;;#make paren gray
(defface paren-face
  '((((class color) (background dark))
     (:foreground "grey50"))
    (((class color) (background light))
     (:foreground "grey50")))
  "Face used to dim parentheses.")
 
;;#mode hook macro
(mapc (lambda (mode)
        (let ((hook (intern (concat (symbol-name mode)    
                                    "-mode-hook"))))    
          (add-hook hook (lambda () (paredit-mode +1)))
           
          (add-hook hook (lambda () (local-set-key (kbd "RET") 'newline-and-indent)))
          (add-hook hook (lambda () (font-lock-add-keywords nil '(("(\\|)" . 'paren-face)))))))
      '(emacs-lisp lisp inferior-lisp slime lisp-interaction scheme))
 
;;#frame size
(add-to-list 'default-frame-alist '(height . 48))
(add-to-list 'default-frame-alist '(width . 80))
(set-frame-position (selected-frame) 0 0)
 
;;#useful shortcut setting
(global-set-key [f3] 'compile)
(global-set-key [f4] 'gdb)

(global-set-key [f5] 'comment-region)
(global-set-key [f6] 'uncomment-region)
 
(global-set-key [f7] 'previous-buffer)
(global-set-key [f8] 'next-buffer)
 
(global-set-key [f12] 'shell)
 
;;#useful settings
(transient-mark-mode t)
(show-paren-mode t)
(global-linum-mode t)

;;#Active Process blah blah
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  "Prevent annoying \"Active processes exist\" query when you quit Emacs."
  (flet ((process-list ())) ad-do-it))
 
;;#Autocomplete
(add-to-list 'load-path "C:/emacs/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "C:/emacs/auto-complete/ac-dict")
(ac-config-default)
(define-key slime-mode-map (kbd "TAB") 'slime-indent-and-complete-symbol)
 
;;#emacs windows
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "VeraGothic" :foundry "unknown" :slant normal :weight normal :height 98 :width normal)))))

2. 리눅스용

MIT Scheme 설정 방법은 블로그 내 다른 글을 참조.

emacs버전이 24.3 미만일 때 auto-pair로드하면 cl-lib때문에 문제가 생긴다. 이 때는 인터넷에서 cl-lib.el을 적절히 구해다가 autopair.el파일이 있는 디렉토리에 넣어주면 된다.


(display-time)

;;Autopair
(add-to-list 'load-path "~/emacs.d/")
(require 'autopair)

;;C/Cpp language
(setq c-basic-offset 8
      c-default-style "linux")
(mapc (lambda (mode)
        (let ((hook (intern (concat (symbol-name mode)    
                                    "-mode-hook"))))    
          (add-hook hook (lambda ()
			   (local-set-key (kbd "RET") 'newline-and-indent)
			   (autopair-mode 1)))))
      '(c c++))
(add-hook 'c-mode-hook
	  (lambda ()
	    (set (make-local-variable 'compile-command)
		 (let ((file (file-name-nondirectory buffer-file-name)))
		   (format "%s %s.c -o %s -g"
			   "gcc"
			   (file-name-sans-extension file)
			   "test")))))
(add-hook 'c++-mode-hook
	  (lambda ()
	    (set (make-local-variable 'compile-command)
		 (let ((file (file-name-nondirectory buffer-file-name)))
		   (format "%s %s.cpp -o %s -g"
			   "g++"
			   (file-name-sans-extension file)
			   "test")))))

;;#slime setting
(add-to-list 'load-path "/usr/share/slime/")
(require 'slime)
(slime-setup '(slime-repl))

;;#paredit setting
(add-to-list 'load-path "/usr/share/emacs/site-lisp/")
(autoload 'paredit-mode "paredit"    
  "Minor mode for pseudo-structurally editing Lisp code." t)

;;#mit-scheme swank setting
(setq slime-lisp-implementations
      '((mit-scheme ("mit-scheme") :init mit-scheme-init)))

(defun mit-scheme-init (file encoding)
  (format "%S\n\n"
	  `(begin
	    (load-option 'format)
	    (load-option 'sos)
	    (eval 
	     '(construct-normal-package-from-description
	       (make-package-description '(swank) '(()) 
					 (vector) (vector) (vector) false))
	     (->environment '(package)))
	    (load ,(expand-file-name 
		    "/usr/share/slime/contrib/swank-mit-scheme.scm" ; <-- insert your path
		    slime-path)
		  (->environment '(swank)))
	    (eval '(start-swank ,file) (->environment '(swank))))))

(defun mit-scheme ()
  (interactive)
  (slime 'mit-scheme))

(defun find-mit-scheme-package ()
  (save-excursion
    (let ((case-fold-search t))
      (and (re-search-backward "^[;]+ package: \\((.+)\\).*$" nil t)
	   (match-string-no-properties 1)))))

(setq slime-find-buffer-package-function 'find-mit-scheme-package)
(add-hook 'scheme-mode-hook (lambda () (slime-mode 1)))

;;slime-repl-mode lisp-indent-fuction
(add-hook 'slime-repl-mode-hook
	  (defun slime-repl-indent-hook ()
	    (set (make-local-variable 'lisp-indent-function)
		 'scheme-indent-function)))

;;skip startup screen and make scheme as major mode
(setq initial-major-mode 'scheme-mode)
(setq inhibit-startup-screen t)



;;#make paren gray
(defface paren-face
  '((((class color) (background dark))
     (:foreground "grey50"))
    (((class color) (background light))
     (:foreground "grey50")))
  "Face used to dim parentheses.")

;;#mode hook macro
(mapc (lambda (mode)
	(let ((hook (intern (concat (symbol-name mode)    
				    "-mode-hook"))))    
	  (add-hook hook (lambda () (paredit-mode +1)))
	  
	  (add-hook hook (lambda () (local-set-key (kbd "RET") 'newline-and-indent)))
	  (add-hook hook (lambda () (font-lock-add-keywords nil '(("(\\|)" . 'paren-face)))))))
      '(emacs-lisp lisp inferior-lisp slime lisp-interaction scheme))

;;#windows size
(add-to-list 'default-frame-alist '(height . 48))
(add-to-list 'default-frame-alist '(width . 80))
(set-frame-position (selected-frame) 0 0)

;;#useful shortcut setting
(global-set-key [f2] 'slime)
(global-set-key [f3] 'slime-repl-clear-buffer)
(global-set-key [f4] 'slime-repl-quit)

(global-set-key [f5] 'comment-region)
(global-set-key [f6] 'uncomment-region)

(global-set-key [f7] 'previous-buffer)
(global-set-key [f8] 'next-buffer)

(global-set-key [f12] 'shell)

;;#useful settings
(transient-mark-mode t)
(show-paren-mode t)
(global-linum-mode t)

;;#Active Process blah blah
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  "Prevent annoying \"Active processes exist\" query when you quit Emacs."
  (flet ((process-list ())) ad-do-it))

;;#Autocomplete
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
(define-key slime-mode-map (kbd "TAB") 'slime-indent-and-complete-symbol)

;;#emacs windows
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "Ubuntu Mono" :foundry "unknown" :slant normal :weight normal :height 98 :width normal)))))


emacs/General