您的位置:首页 > 其它

emacs配置文件中比较好用的函数

2013-04-27 19:00 405 查看

(声明:这些函数非本人原创,是本人从各处收集的,后期还会更新)

1.在当前行之前,之后插入新行(类似与vim在normal模式下的a和o键)

出处(http://whattheemacsd.com/)
;;C-return 在当前行上新开一行
;;C-S-return 在当前行下新开一行
(defun open-line-below ()
(interactive)
(end-of-line)
(newline)
(indent-for-tab-command))

(defun open-line-above ()
(interactive)
(beginning-of-line)
(newline)
(forward-line -1)
(indent-for-tab-command))

(global-set-key (kbd "<C-return>") 'open-line-below)
(global-set-key (kbd "<C-S-return>") 'open-line-above)


C即ctrl键,S即shift键盘;
使用elisp语言定义了两个函数,open-line-below和open-line-above.
open-line-below是在当前行之下插入新行,open-line-above实在当前行之上插入新行
将这两个函数分别映射到了<C-return>和<C-S-return>两个快捷键上.

2.emacs全屏

出处(Deepin linux emacs中的配置)
;;; fullscreen.el --- Full screen

;; Filename: fullscreen.el
;; Description: Full screen
;; Author: Andy Stewart <lazycat.manatee@gmail.com>
;; Maintainer: Andy Stewart <lazycat.manatee@gmail.com>
;; Copyright (C) 2009, Andy Stewart, all rights reserved.
;; Created: 2009-02-11 21:05:32
;; Version: 0.1
;; Last-Updated: 2009-02-11 21:05:32
;;           By: Andy Stewart
;; URL: http://www.emacswiki.org/emacs/download/fullscreen.el ;; Keywords: fullscreen
;; Compatibility: GNU Emacs 23.0.60.1
;;
;; Features that might be required by this library:
;;
;;
;;

;;; This file is NOT part of GNU Emacs

;;; License
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.

;;; Commentary:
;;
;; Full screen.
;;
;; Below are commands you can use:
;;
;; `fullscreen'         Full screen.
;; `fullscreen-toggle'  Toggle full screen status.
;;

;;; Installation:
;;
;; Put fullscreen.el to your load-path.
;; The load-path is usually ~/elisp/.
;; It's set in your ~/.emacs like this:
;; (add-to-list 'load-path (expand-file-name "~/elisp"))
;;
;; And the following to your ~/.emacs startup file.
;;
;; (require 'fullscreen)
;;
;; No need more.

;;; Customize:
;;
;;
;;
;; All of the above can customize by:
;;      M-x customize-group RET fullscreen RET
;;

;;; Change log:
;;
;; 2009/02/11
;;      * First released.
;;

;;; Acknowledgements:
;;
;;
;;

;;; TODO
;;
;;
;;

;;; Require

;;; Code:

(defun fullscreen ()
"Fullscreen."
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
;; if first parameter is '1', can't toggle fullscreen status
'(1 "_NET_WM_STATE_FULLSCREEN" 0)))

(defun fullscreen-toggle ()
"Toggle fullscreen status."
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
;; if first parameter is '2', can toggle fullscreen status
'(2 "_NET_WM_STATE_FULLSCREEN" 0)))

(provide 'fullscreen)

;;; fullscreen.el ends here
将上面这段代码复制下来,保存为fullscreen.el,在.emacs中加入fullscreen.el的路径,在.emacs加入以下代码:
(require 'fullscreen)
(global-set-key [f11] 'fullscreen-toggle)
绑定到了快捷键F11上,按一次最大化,再按一次又恢复了,很方便

效果图:



3.重命名当前缓冲区

;;快捷键 C-x C-r重命名当前缓冲区
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))

(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)
快捷键绑定到了ctrl-x ctrl-r上
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Emacs