emacs 配置

1. 参考资料

2. 配置

<span style="font-size:18px;">base.el</span>

;;=======================================================================
;;Author:guoyao
;;Date:2014-12-27
;;Update Date:2014-12-27
;;=======================================================================

;;===============================display===============
;;----------------time---------------------
(display-time-mode 1);;启用时间显示设置,在minibuffer上面的那个杠上
(setq display-time-24hr-format t);;时间使用24小时制
(setq display-time-day-and-date t);;时间显示包括日期和具体时间
(setq display-time-interval 10);;时间的变化频率,单位多少来着?

;;显示列号
(setq column-number-mode t)

;;没列左边显示行号,按f3显示/隐藏行号
(require 'linum)
(global-linum-mode)

;;显示标题栏 %f 缓冲区完整路径 %p 页面百分数 %l 行号
(setq frame-title-format "%f")

;;防止页面滚动时跳动, scroll-margin 3 可以在靠近屏幕边沿3行时就开始滚动,可以很好的看到上下文
(setq scroll-margin 3  scroll-conservatively 10000)

;; 去掉滚动条
(set-scroll-bar-mode nil)
;;关闭开启画面
(setq inhibit-startup-message t)
;;禁用工具栏
(tool-bar-mode -1)
;;禁用菜单栏
(menu-bar-mode -1)


;;设定行距
(setq default-line-spaceing 4)
;;页宽
(setq default-fill-column 60)

;;将错误信息显示在回显区
(condition-case err
	(progn
	  (require 'xxx))
  (error
   (message "Can't load xxx-mode %s" (cdr err))))


;;------------------style--------------
(load "D:/user/emacs/.emacs_dir/lib/color-theme.el")
(color-theme-initialize)
(color-theme-arjen)

(setq default-frame-alist
	  '((height . 50)(width . 100)(menubar-lines . 20)(tool-bar-lines . 0)))


;;锁定行高
(setq resize-mini-windows nil)
;;只渲染当前屏幕语法高亮,加快显示速度
(setq lazy-lock-defer-on-scrolling t)


;;光标形状
(setq-default cursor-type 'bar)
;;----光标靠近时鼠标挪开-----------------
(mouse-avoidance-mode 'animate)


;; 当光标在行尾上下移动的时候,始终保持在行尾。
(setq track-eol t)

;;闪屏报警
(setq visible-bell t)
;;使用y or n提问
(fset 'yes-or-no-p 'y-or-n-p)


;;=================text==============
;;开启语法高亮。
(global-font-lock-mode 1)
;;高亮显示区域选择
(transient-mark-mode t)

;;高亮显示成对括号
(show-paren-mode t)
(electric-pair-mode)

;;设置TAB宽度为4
(setq default-tab-width 4) 
;;以下设置缩进
;;用tab缩进
(setq indent-tabs-mode nil)
(setq c-indent-level 4)
(setq c-continued-statement-offset 4)
(setq c-brace-offset -4)
(setq c-argdecl-indent 4)
(setq c-label-offset -4)
(setq c-basic-offset 4)
(global-set-key "\C-m" 'reindent-then-newline-and-indent)

;; 自动的在文件末增加一新行
(setq require-final-newline t)

;;粘贴于光标处,而不是鼠标指针处
(setq mouse-yank-at-point t)



;;当你在shell、telnet、w3m等模式下时,必然碰到过要输入密码的情况,此时加密显出你的密码
(add-hook 'comint-output-filter-functions
		  'comint-watch-for-password-prompt)


;;==========================================

;;设置缺省主模式是text,,并进入auto-fill次模式.而不是基本模式fundamental-mode
(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill) 


(setq x-select-enable-clipboard t)
;;不产生备份文件
(setq make-backup-files nil)
;;不生成临时文件
(setq-default make-backup-files nil)


;;设置删除记录
(setq kill-ring-max 200)

;;自动重载更改的文件
(global-auto-revert-mode 1)
;;custome的风格改为单一的树状风格
(setq custom-buffer-style 'brackets)

(setq show-paren-style 'parentheses)

;;递归minibuffer
(setq enable-recursive-minibuffers t)

;;设置自定义变量
(custom-set-variables
 '(mouse-1-click-in-non-selected-windows t)
 '(save-place t nil (saveplace)))


;;================tool======================
;;-------------ibuffer,查看bufer
(require 'ibuffer)
(global-set-key ( kbd "C-x C-b")' ibuffer)
;;------------------ido-----------------------
;;ido的配置,这个可以使你在用C-x C-f打开文件的时候在后面有提示;
;;这里是直接打开了ido的支持,在emacs23中这个是自带的.
(ido-mode t)


;;让 dired 可以递归的拷贝和删除目录。
(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes 'top)


<span style="font-size:18px;">;;cykbd.el
</span>;;=============================================

;;===========================================================
;;键绑定
;;===========================================================


(global-set-key (kbd "C-z") 'kill-this-buffer)

;;.emacs中设一个speedbar的快捷键
(global-set-key [(f4)] 'speedbar-get-focus)

(global-set-key [f6] 'gdb)

;;  C-f7, 设置编译命令; f7, 保存所有文件然后编译当前窗口文件
(defun du-onekey-compile ()
  "Save buffers and start compile"
  (interactive)
  (save-some-buffers t)
  (switch-to-buffer-other-window "*compilation*")
  (compile compile-command))
  
(setq-default compile-command "make")    
(global-set-key [C-f7] 'compile)
(global-set-key [f7] 'du-onekey-compile)

;;目的是开一个shell的小buffer,用于更方便地测试程序(也就是运行程序了),我经常会用到。
;;f8就是另开一个buffer然后打开shell,C-f8则是在当前的buffer打开shell,shift+f8清空eshell
(defun open-eshell-other-buffer ()
  "Open eshell in other buffer"
  (interactive)
  (split-window-horizontally)
  (eshell)
  )
(global-set-key [(f8)] 'open-eshell-other-buffer)
(global-set-key [C-f8] 'eshell)


;;设置F10为撤销
(global-set-key (kbd "C-/") 'undo)

;;设置F11快捷键指定Emacs 的日历系统
(global-set-key [C-f11] 'calendar) 

(global-set-key (kbd "C-,") 'previous-buffer)
(global-set-key (kbd "C-.") 'next-buffer)


;;设置M-g为goto-line
(global-set-key (kbd "M-g") 'goto-line)

;;取消control+space键设为mark
(global-set-key (kbd "C-SPC") 'nil)


;;关闭当前窗口,alt+4
(global-set-key (kbd "M-5") 'delete-window)
;;关闭其他窗口,alt+1
(global-set-key (kbd "M-1") 'delete-other-windows)
;;水平分割窗口,alt+2
(global-set-key (kbd "M-4") 'split-window-vertically)
;;垂直分割窗口,alt+3

(defun split-window-horizontally-1()
  (interactive)
  (split-window-horizontally)
  (next-multiframe-window)
)
(global-set-key (kbd "M-`") 'split-window-horizontally-1)
;;切换到其他窗口,alt+0
(global-set-key (kbd "M-2") 'previous-multiframe-window)
(global-set-key (kbd "M-3") 'next-multiframe-window)
;;================================================================

(global-set-key (kbd "C-2") 'set-mark-command)

;;----------------------------------------------------------------------------
(global-set-key (kbd "M-p") 'c-beginning-of-defun)
(global-set-key (kbd "M-n") 'c-end-of-defun)


(global-set-key (kbd "C-0") 'forward-sexp)
(global-set-key (kbd "C-9") 'backward-sexp)

;;--------------代码折叠-------------------------
(add-hook 'c-mode-hook 'hs-minor-mode)
(add-hook 'c++-mode-hook 'hs-minor-mode)

(global-set-key (kbd "C--") 'hs-hide-all)
(global-set-key (kbd "C-=") 'hs-show-all)
(global-set-key (kbd "M--") 'hs-hide-block)
(global-set-key (kbd "M-=") 'hs-show-block)

;;-------------自动插入成对的括号----------------------
(add-hook 'c-mode-hook 'electric-pair-mode)
(add-hook 'lisp-interaction-mode 'electric-pair-mode)



a.el 中是一些自定义的函数

<span style="font-size:18px;">;;a.el</span>
;;=======================================================================

(defun wy-go-to-char (n char)  
  "Move forward to Nth occurence of CHAR.  
Typing `wy-go-to-char-key' again will move forwad to the next Nth  
occurence of CHAR."  
  (interactive "p\ncGo to char: ")  
  (search-forward (string char) nil nil n)
  (backward-char)
  (while (char-equal (read-char)  
					 char)  
	(progn (forward-char)
		   (search-forward (string char) nil nil n)
		   (backward-char)
		   )
	)
(setq unread-command-events (list last-input-event)))
(define-key global-map (kbd "C-v") 'wy-go-to-char)


;;-------------?s 怎么换成C-s 序列-------------
(defun search-word-forward()
  (interactive)
  (setq cur-word (word-at-point))
  (search-forward cur-word nil t 1)
  (while (char-equal (read-char) ?s)
	(search-forward cur-word nil t 1)
	)
  ;;--------------useful var--------------
  (setq unread-command-events (list last-input-event))
  )
(global-set-key (kbd "C-s") 'search-word-forward)
(global-set-key (kbd "C-c C-s") 'isearch-forward)


(defun search-word-backward()
  (interactive)
  (setq cur-word (word-at-point))
  (search-backward cur-word nil t 1)
  (while (char-equal (read-char) ?r)
	(search-backward cur-word nil t 1)
	)
  ;;--------------useful var--------------
  (setq unread-command-events (list last-input-event))
  )
(global-set-key (kbd "C-r") 'search-word-backward)
(global-set-key (kbd "C-c C-r") 'isearch-backward)


(defun my-highlight-symbol()
  (interactive)
  (hi-lock-face-symbol-at-point)
  )
(global-set-key [f1] 'my-highlight-symbol)

(defun my-unhighlight-symbol()
  (interactive)
  (hi-lock-unface-buffer (concat "\\_<" (format "%S" (symbol-at-point)) "\\_>"))
  )
(global-set-key [M-f1] 'my-unhighlight-symbol)



;;-------highlight ---------------------------------
(defun my-highlight-word()
  (interactive)
  (hi-lock-face-buffer  (word-at-point))
  )
(global-set-key [f3] 'my-highlight-word)

(defun my-unhighlight-word()
  (interactive)
  (hi-lock-unface-buffer (word-at-point))
  )
(global-set-key [M-f3] 'my-unhighlight-word)
;;--------------highlight--------------------

(defun yank-and-indent ()
  (interactive)
  (setq begin-line (line-number-at-pos))
  (yank)
  (setq end-line (line-number-at-pos))
  (while (>= end-line begin-line)
	(progn (goto-line begin-line)	
	(c-indent-line-or-region)
	(setq begin-line (+ begin-line 1))
	)
	)
  (end-of-line)
  )
(global-set-key (kbd "C-y") 'yank-and-indent)


(defun copy-line-1()
  (interactive)
  (setq cur-point (point))
  (kill-ring-save (line-beginning-position) (line-end-position))
  (goto-char cur-point)
  )

(defun copy-intelligent()
  (interactive)
  (setq cur-point (point))
  (if (equal mark-active nil)
	  (copy-line-1)
	(kill-ring-save (mark) (point))
	)
  )
(global-set-key (kbd "C-q") 'copy-intelligent)

(defun cut-line-1()
  (interactive)
  (kill-region (line-beginning-position) (line-end-position))
  )

(defun cut-intelligent()
  (interactive)
  (if (equal mark-active nil)
	  (cut-line-1)
	(kill-region (mark) (point))
	(setq kill-ring kill-ring)
	))

(global-set-key (kbd "C-w") 'cut-intelligent)


(defun next-7-line ()"next 7 lines"
	   (interactive)
	   (next-line 7))

(global-set-key (kbd "C-j") 'next-7-line)

(defun previous-7-line ()"next 7 lines"
	   (interactive)
	   (previous-line 7))

(global-set-key (kbd "C-;") 'previous-7-line)

(defun qiang-comment-dwim-line (&optional arg)
  "Replacement for the comment-dwim command. If no region is selected and current line is not blank and we are not at the end of the line, then comment current line. Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
  (interactive "*P" )
  (comment-normalize-vars)
  (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
      (comment-or-uncomment-region (line-beginning-position) (line-end-position))
    (comment-dwim arg)))
(global-set-key "\M-;" 'qiang-comment-dwim-line)


(defun my-new-line-and-indent (arg)
  (interactive "^p")
  (or arg (setq arg 1))
  (let (done)
    (while (not done)
      (let ((newpos
         (save-excursion
           (let ((goal-column 0)
             (line-move-visual nil))
         (and (line-move arg t)
              (not (bobp))
              (progn
            (while (and (not (bobp)) (invisible-p (1- (point))))
              (goto-char (previous-single-char-property-change
                                      (point) 'invisible)))
            (backward-char 1)))
         (point)))))
    (goto-char newpos)
    (if (and (> (point) newpos)
         (eq (preceding-char) ?\n))
        (backward-char 1)
      (if (and (> (point) newpos) (not (eobp))
           (not (eq (following-char) ?\n)))
          ;; If we skipped something intangible and now we're not
          ;; really at eol, keep going.
          (setq arg 1)
        (setq done t))))))
 (newline-and-indent))

(define-key global-map (kbd "C-<return>") 'my-new-line-and-indent)

(define-skeleton skeleton-c-mode-functioncomment-func
  "generate function comment automatic" nil
  "/*********************************\n* 函数名 :\n* 功能描述 :\n* 作者 :  \n* 输入参数 : \n* 输出参数 : \n* 返回值 : \n* 历史记录 : \n*\n*********************************/"
  > _  "" > ""
  )
(define-abbrev-table 'c-mode-abbrev-table '(
    ("funccomm" "" skeleton-c-mode-functioncomment-func 1)
    ))
(define-abbrev-table 'c++-mode-abbrev-table '(
    ("funccomm" "" skeleton-c-mode-functioncomment-func 1)
    ))

;;----------------------------------------------------------------------------
;;-----------------------将emacs 的kill 换成delete------------------------
(defun delete-line () "delete line, take it out of kill ring. bind this func to C-z"
	   (interactive)
	   (beginning-of-line)				
	   (kill-whole-line)
	   
	   (setq kill-ring (cdr kill-ring))
	   (setq kill-ring-yank-pointer kill-ring)
	   (setq last-command 'kill-whole-line)
	   )

(defun delete-intelligent()
  (interactive)
  (if (equal mark-active nil)
	  (delete-line)
	(progn(kill-region (mark) (point))
		  (setq kill-ring (cdr kill-ring))
		  (setq kill-ring-yank-pointer kill-ring)
		  )

	)
  )
(global-set-key (kbd "C-k") 'delete-intelligent)


;;-------------------for test------------------
(setq brace-list-left '(?{ ?( ?[))
(setq brace-list-right '(?} ?) ?]))


(defun find-brace-left(arg)
  (interactive)
  (goto-char arg)
  (setq brace-count 1)
  (while (not (equal brace-count 0))
	(progn
	  (cond
	   ((member (char-before) brace-list-right)
		(setq brace-count (+ 1 brace-count)))
	   ((member (char-before) brace-list-left)
		(setq brace-count (- brace-count 1)))
	   ((eq (char-before) ?\")
		(progn
		  (backward-char)
		  (search-backward (string ?\") nil t 1)
		  (forward-char))
		)

	   )
	  (backward-char)
	  ))
  (point)
  )

(defun find-brace-right(arg)
  (interactive)
  (goto-char arg)
  (setq brace-count 1)
  (while (not (equal brace-count 0))
  	(progn
  	  (cond
  	   ((member (char-after) brace-list-left)
  		(setq brace-count (+ 1 brace-count)))
  	   ((member (char-after) brace-list-right)
  		(setq brace-count (- brace-count 1)))
  	   ((eq (char-after) ?\")
  		(progn
  		  (forward-char)
		  (search-forward (string ?\") nil t 1)
  		  (backward-char)
  		  )
  		)
  	   )
  	  (forward-char)
  	  ))
  (point)
  )


;;------------------假设光标位置不在引号内, 如果在引号内会出错-----------------
;;------------对注释内容没有处理, 但勉强能用
(defun find-block ()
  (interactive)
  (setq gy-cur-point (point))
  (setq bp (find-brace-left gy-cur-point))
  (setq ep (find-brace-right gy-cur-point))
  (kill-region bp ep)
  )
(global-set-key (kbd "C-l") 'find-block)


;;-----------------------------------------



;;------------------------------------------------------------

(defun delete-word() "delete word, take it out of kill ring. bind this func to M-d"
 (interactive)
 (setq last-command 'delete-word)
 (kill-word 1)
 (setq kill-ring (cdr kill-ring))
 (setq kill-ring-yank-pointer kill-ring)
 (setq last-command 'delete-word-backward)
)
(global-set-key (kbd "M-d") 'delete-word)

(global-set-key (kbd "C-<backspace>") 'backward-delete-char)


(defun delete-word-backward() "delete word, take it out of kill ring. bind this func to M-d"
 (interactive)
 (setq last-command 'delete-word-backward)
 (backward-kill-word 1)
 (setq kill-ring (cdr kill-ring))
 (setq kill-ring-yank-pointer kill-ring)
 (setq last-command 'delete-word-backward)
)
(global-set-key (kbd "M-<backspace>") 'delete-word-backward)







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值