再一次,写一个最简单的.emacs

 

新装一个特殊的linux开发机器,使用的是ubuntu。默认还是用emacs开发,这两天尝试做尽可能少的定制,最终的.emacs是我觉得非加不可的一些设置。


;;;must key
(global-set-key (kbd "M-h") (lambda () (interactive) (find-file "~/.emacs")))
(global-set-key (kbd "M-SPC") 'set-mark-command)
(global-set-key (kbd "C-x k") (lambda () (interactive) (kill-buffer (current-buffer))))
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-x C-3") 'server-edit)
(global-set-key (kbd "C-'") 'server-edit)
(global-set-key (kbd "C-c o") 'occur)
(global-set-key (kbd "<f7>") 'compile)
(global-set-key (kbd "M-o") 'jr-find-alt-buf-or-file)

;;;must mode
(ido-mode)
(transient-mark-mode 0)
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)

;;;must UI
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
  (scroll-bar-mode -1))
(when (fboundp 'menu-bar-mode)
  (menu-bar-mode -1))
(set-default-font "Source Code Variable 10")
(add-to-list 'default-frame-alist (cons 'font "Source Code Variable 10"))
(defun cc-font (font)
  (ignore-errors
    (dolist (charset '(kana han symbol cjk-misc bopomofo))
      (set-fontset-font (frame-parameter nil 'font)
			charset
			(font-spec :family font :size 12)))))
;; (cc-font "Source Han Sans")
;; (cc-font "PingFang SC")
;; (cc-font "STHeiTi")
;; (cc-font "Microsoft YaHei")
(cc-font "Hiragino Sans GB")

;;;;;;;;;;;;;;;;;;;;;;;;must jr code
(defun jr-flip-file-name (fn)
  (cond ((string-match ".*\\.cpp" fn)
         (replace-regexp-in-string "\\.cpp" ".h" fn))
        ((string-match ".*\\.h" fn)
         (replace-regexp-in-string "\\.h" ".cpp" fn))
        (t "")))
(defun jr-find-alt-buf-or-file ()
  "switch between .h .cpp"
  (interactive)
  (let* ((fn (buffer-name))
         (ffn (buffer-file-name))
         (fn-new (jr-flip-file-name fn))
         (ffn-new (jr-flip-file-name ffn)))
    (cond ((memq (get-buffer fn-new)
                 (buffer-list))
           (switch-to-buffer (get-buffer fn-new)))
          ((and (> (length ffn-new) 0) (file-exists-p ffn-new))
           (find-file ffn-new)))))
;;;;;;;;;;;;;;;;;;;;;;;;jr code end

;;;must hook
(defun my-c-mode-hook ()
  (c-set-style "stroustrup"))
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)
(setq jr-customize-bg-color "black")
(when window-system
  (setq jr-customize-bg-color "#314f4f"))
;(server-start)

(custom-set-variables
  ;; custom-set-variables 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-tab-width 4 t)
 '(frame-title-format (quote ("%b || Emacs ||" (:eval (current-time-string)))) t)
 '(inhibit-startup-screen t)
 '(truncate-lines t))
(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 (:background "#314f4f")))))


(when (not window-system)
  (custom-set-faces
 '(default ((t (:background "black"))))))

 

 

更新了使用global和.cr_root文件的版本~已经不算简了。

 

;;;must key
(global-set-key (kbd "M-h") (lambda () (interactive) (find-file "~/.emacs")))
(global-set-key (kbd "M-SPC") 'set-mark-command)
(global-set-key (kbd "M-[") 'set-mark-command)
(global-set-key (kbd "C-x k") (lambda () (interactive) (kill-buffer (current-buffer))))
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-x C-3") 'server-edit)
(global-set-key (kbd "C-'") 'server-edit)
(global-set-key (kbd "C-c o") 'occur)
(global-set-key (kbd "C-c g") 'jr-global-tag)
(global-set-key (kbd "C-c r") 'jr-global-root-file)
(global-set-key (kbd "<f7>") 'compile)
(global-set-key (kbd "M-o") 'jr-find-alt-buf-or-file)

;;;must mode
(ido-mode)
(transient-mark-mode 0)
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)

;;;must UI
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
  (scroll-bar-mode -1))
(when (fboundp 'menu-bar-mode)
  (menu-bar-mode -1))


;;;;;;;;;;;;;;;;;;;;;;;;must jr code
(defun jr-global-tag ()
  (interactive)
  (ignore-errors (kill-buffer "*GTAGS*"))
  (save-excursion
	(let ((buf)
		  (tag (read-string "Tag:")))
	  (setq buf (pop-to-buffer "*GTAGS*"))
	  (setq tag (replace-regexp-in-string "\\*" ".*" tag))
	  (make-local-variable 'compilation-error-regexp-alist)
	  (compilation-minor-mode)
	  (add-to-list 'compilation-error-regexp-alist
				   '("\\sw+\\s +\\([0-9]+\\)\\s +\\([^ ]+\\)" 2 1))
	  (start-process "GTAG" buf "global" "-x" "-i" tag)
	  (set-process-sentinel (get-buffer-process (current-buffer))
							(lambda (process event)
							  (when (string-match "finished" event)
								(goto-char (point-max))
								(insert
								 (format "Process: %s had finished" process))
								(goto-char (point-min))
								(font-lock-mode)))))))

(defun jr-global-root-file ()
  (interactive)
  (ignore-errors (kill-buffer "*GROOT*"))
  (save-excursion
	(let ((buf)
		  (name (read-string "Name:")))
	  (setq buf (pop-to-buffer "*GROOT*"))
	  (setq name (replace-regexp-in-string "\\*" ".*" name))
	  (make-local-variable 'compilation-error-regexp-alist)
	  (while (or (not (file-exists-p ".cr_root"))
				 (not (string-match "/\\|\\(.:/\\)" default-directory)))
		(cd ".."))
	  (when (not (file-exists-p ".cr_root"))
		(message "no .cr_root founded"))
	  (compilation-minor-mode)
	  (add-to-list 'compilation-error-regexp-alist
				   '("\\([^\n ]+\\)" 1))
	  (start-process "GROOT" buf "grep" "-i" name ".cr_root")
	  (set-process-sentinel (get-buffer-process (current-buffer))
							(lambda (process event)
							  (when (string-match "finished" event)
								(goto-char (point-max))
								(insert
								 (format "Process: %s had finished" process))
								(goto-char (point-min))
								(font-lock-mode)))))))

(defun jr-flip-file-name (fn)
  (cond ((string-match ".*\\.cpp" fn)
		 (replace-regexp-in-string "\\.cpp" ".h" fn))
		((string-match ".*\\.h" fn)
		 (if (replace-regexp-in-string "\\.h" ".cpp" fn)
			 (replace-regexp-in-string "\\.h" ".cpp" fn)
		   (replace-regexp-in-string "\\.h" ".c" fn)))
		(t "")))
(defun jr-find-alt-buf-or-file ()
  "switch between .h .cpp"
  (interactive)
  (let* ((fn (buffer-name))
		 (ffn (buffer-file-name))
		 (fn-new (jr-flip-file-name fn))
		 (ffn-new (jr-flip-file-name ffn)))
	(cond ((memq (get-buffer fn-new)
				 (buffer-list))
		   (switch-to-buffer (get-buffer fn-new)))
		  ((and (> (length ffn-new) 0) (file-exists-p ffn-new))
		   (find-file ffn-new)))))
(defun eshell/clear ()
  "04Dec2001 - sailor, to clear the eshell buffer."
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)))
(defalias 'e/c 'eshell/clear)
;;;;;;;;;;;;;;;;;;;;;;;;jr code end

;;;must hook
(defun my-c-mode-hook ()
  (c-set-style "stroustrup"))
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)
(setq jr-customize-bg-color "black")
(when window-system
  (setq jr-customize-bg-color "#314f4f"))
(server-start)

(custom-set-variables
  ;; custom-set-variables 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-tab-width 4 t)
 '(frame-title-format (quote ("%b || Emacs ||" (:eval (current-time-string)))) t)
 '(inhibit-startup-screen t)
 '(truncate-lines t))
(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 (:background "#314f4f")))))


(when (not window-system)
  (custom-set-faces
 '(default ((t (:background "black"))))))
(put 'dired-find-alternate-file 'disabled nil)

 

 

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值