定制Emacs环境

1:Hiding the tool bar

  方式一:Option -> Show/shadow -> Tool bar

  方式二:通过custom interface 更改.emacs 文件

(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.
 '(tool-bar-mode nil nil (tool-bar)))

2:Turning on CUA mode

If you're new to Emacs, you might be used to the Common User Access (CUA) conventions for cutting, copying, and pasting, C-x, C-c, and C-v respectively.You might reach for C-z for undo.CUA mode was once an add-on mode that you had to install separately, but it became so popular that it is now part of Emacs. It's coded in a clever way that doesn't interfere with Emacs keystrokes that are prefixed with C-x and C-c. 

  方式一:Option -> C-x/C-c/C-v cut and paste(CUA)

  方式二:如下设置在.emacs

(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.
 '(cua-mode t nil (cua-base))
 '(tool-bar-mode nil nil (tool-bar)))
3:Text-mode和Auto-fill mode
   同样我们可以通过设置.emacs文件来实现把Text-mode作为默认主模式,并且在Text-mode模式下自动设为值自动换行的副模式,注意该副模式只是针对Text-mode作为主模式情况下的。

(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook  'turn-on-auto-fill)

另一种方式在Text-mode模式下自动添加自动换行模式:Option -> Line wrapping in this buffer -> word wrap

4:search Case-sensitive

  具体原因见查找和替换中大小写

(setq-default case-fold-search nil)  ; require exact matches
(setq-default case-replace nil)      ; never change case when replacing

5: flyspell-modeInterpretation

To enter flyspell mode automatically, add this line to your .emacs file 

(setq-default flyspell-mode t)

6:Word abbreviations

To define word abbreviation and make them part of your startup:

(setq-default abbrev-mode t)
(read-abbrev-file "~/.abbrev_defs")
(setq save-abbrevs t)
first time when you start Emacs, it will say Emacs cant load your abbrev file, because you haven't create the file yet, it wont happen again.

7: Subsequent Frame

These lines set up sizes for the width and height of Emacs frames. The first frame is the size set in initial-frame-alist (in this example, 90 characters wide by 50 lines high with top and left defining an inset), and subsequent frames, specified by default-frame-alist, will be 80 characters wide and 45 lines high.

(setq initial-frame-alist '((top . 10) (left . 30)
                            (width . 90) (height . 50)))
(setq default-frame-alist '((width . 80) (height . 45)))

8: Passwords invisible in shell mode

M-x send-invisible before you type password,then type this command.. Emacs will ask for non-echoed text.Then to have emacs hide your password as you type them.

(add-hook 'comint-output-filter-functions
   'comint-watch-for-password-prompt)

9: auto-compress-mode

在emacs里面你可以直接编辑压缩文件,Emacs has an automatic compression/decompression mode called auto-compress mode.你可以输入命令M-x auto-compress-mode RET 或者加入下面到.emacs文件

(auto-compression-mode           1)

10: Calendar

if you want to have the calendar always start on Monday, Type M-x set-variable RET calendar-week-start RET 1 RET  or add below in .emacs

(setq calendar-week-start-day 1)

11: automatically display calendar and diary entry

(calendar)
(diary)          只会在有日程的那天显示,但是会被calendar覆盖。所以要考虑清楚。

12: Font and Font-lock

;; Turn on font-locking globally
(global-font-lock-mode t)

13: C style in C-mode

M-x c-style-set 然后输入Tab键显示所支持的格式

(add-hook 'c-mode-hook
       '(lambda ( )
         (c-set-style "stylename")))

14: auto-newline and hungry-delete-key in C-mode

C-c C-a  C-toggle-auto-state (c)->(c/a)  in mode line

C-c C-d  c-toggle-hungry-state 它同样是一个toggle,输入以后mode line 会显示(C/h)

(add-hook 'c-mode-hook
      '(lambda ( )
          (c-toggle-auto-state)
	  (c-toggle-hungry-state)
	  ))

15: auto-save-interval

the number of keystrokes between auto-saves

(setq auto-save-interval 800)

16: Rect-mark

download Rect-mark.el through http://www.emacswiki.org/cgi-bin/wiki/rect-mark.el , then add rect-mark-.el file to your load-path. at last add below to your .emacs file

pay attention: it will collision with CUA key set up. you should close CUA first, or it will not highlight even though you move point with arrow.

;;for rectangel
;; ;; Support for marking a rectangle of text with highlighting.
(define-key ctl-x-map "r\C-@" 'rm-set-mark)                                               ;; C-x r C-@ RET -> mini-buffer 'mark set' -> move point with arrow
(define-key ctl-x-map [?r ?\C-\ ] 'rm-set-mark)
(define-key ctl-x-map "r\C-x" 'rm-exchange-point-and-mark)
(define-key ctl-x-map "r\C-w" 'rm-kill-region)
(define-key ctl-x-map "r\M-w" 'rm-kill-ring-save)
(define-key global-map [S-down-mouse-1] 'rm-mouse-drag-region)
(autoload 'rm-set-mark "rect-mark"   
   "Set mark for rectangle." t)
(autoload 'rm-exchange-point-and-mark "rect-mark"
   "Exchange point and mark for rectangle." t)
(autoload 'rm-kill-region "rect-mark"
   "Kill a rectangular region and save it in the kill ring." t)
(autoload 'rm-kill-ring-save "rect-mark"
   "Copy a rectangular region to the kill ring." t)
(autoload 'rm-mouse-drag-region "rect-mark"
   "Drag out a rectangular region with the mouse." t)

;; Use this section in your "~/.emacs" to modify picture mode so that
;; it automatically uses the rect-mark equivalents of many commands.

;; ;; One vision of a better picture mode.
;; (add-hook 'picture-mode-hook 'rm-example-picture-mode-bindings)
;; (autoload 'rm-example-picture-mode-bindings "rect-mark"
;;   "Example rect-mark key and mouse bindings for picture mode.")

17 autopairs

down load autopair.el on https://raw.github.com/capitaomorte/autopair/master/autopair.el

detail info for

autopair    https://github.com/capitaomorte/autopair#neat-tricks

autopair     http://www.emacswiki.org/emacs/AutoPairs

textmate    https://github.com/ramblex/emacs-textmate

yasnippet http://www.emacswiki.org/emacs/Yasnippet

(require 'autopair)
(autopair-global-mode) ;; enable autopair in all buffers

because autopairs has lots of incompatibility with other tool,such as auto-complete

(defun my-common-mode-auto-pair ()
  (interactive)
  (make-local-variable 'skeleton-pair-alist)
  (setq skeleton-pair-alist  '(
			       (? ? _ "''")
			       (? ? _ """")
			       (? ?  _ "()")
			       (? ?  _ "[]")
			       (?{ \n > _ \n ?} >)))
  (setq skeleton-pair t)
  (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "\'") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "[") 'skeleton-pair-insert-maybe))
(add-hook 'c-mode-hook 'my-common-mode-auto-pair)
(add-hook 'c++-mode-hook 'my-common-mode-auto-pair)
(add-hook 'java-mode-hook 'my-common-mode-auto-pair)
(add-hook 'lisp-mode-hook 'my-common-mode-auto-pair)
(add-hook 'php-mode-hook 'my-common-mode-auto-pair)
(add-hook 'python-mode-hook 'my-common-mode-auto-pair)
(add-hook 'html-mode-hook 'my-common-mode-auto-pair)
(add-hook 'scheme-mode-hook 'my-common-mode-auto-pair)
(add-hook 'css-mode-hook 'my-common-mode-auto-pair)
(add-hook 'sql-mode-hook 'my-common-mode-auto-pair)
(add-hook 'emacs-lisp-mode-hook 'my-common-mode-auto-pair)
(add-hook 'text-mode-hook 'my-common-mode-auto-pair)
(add-hook 'slime-repl-mode-hook 'my-common-mode-auto-pair)

18: auto-complete

auto-complete http://emacswiki.org/emacs/AutoComplete

                          Auto Complete Mode User Manual

;;because i found auto-complete is conflicted with auto-pair.when the appropriate word
;;is appeared, then i type RET,it will be newline.can't select the word.
;;(ac-set-trigger-key "RET")
;; It's will be TAB to trigger completion
(ac-set-trigger-key "TAB") 
;; auto completion start when there are not less than 4 chars
(setq ac-auto-start 4)

;; I hava tried below command but not working, i dont know why
;; disable auto-complete
;;(setq ac-auto-start nil)
;; bind to global key to auto-complete command
;;(global-set-key "\M-/" 'auto-complete)
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue")


link:

http://www.emacswiki.org/cgi-bin/wiki 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值