Emacs才是世界上最强的IDE - 智能的改变光标形状
Emacs默认情况下, Emacs的光标是一个小方块, 相比一般程序里面的一个小长条形状, 可以很快的在一大片文字中看到当前光标在哪, 但是缺点就是, 在编辑的时候不太方便, 因为那个小方块是覆盖在整个字母上的, 很多人刚开始用的时候都不知道当他敲进一个字母的时候, 这个字母是插到当前字母的后面还是前面, 这点, 光标显示为小长条就比较容易分辨了, 那么我们怎么结合它们两者的优点呢? Emacs再一次体现了它那强大的扩展性, cursor-chg正是利用了Emacs的扩展性, 得以成功结合上述两种光标的优点, 它在以下方面进行改进:
- 当你在Emacs中操作的时候, 光标为长条状, 就像这样:
一旦你不操作Emacs, Emacs处于空闲状态时, 光标就由长条状变成方块状, 这样方便你定位光标, 因为Emacs处于空闲状态, 说明你正在盯着Emacs看文本, 或者你离开了一会, 不在编辑状态, 变成方块状方便你定位光标. - 当当前buffer为只读buffer, 或者当前编辑模式为覆写模式(你按了一下insert键), 或者你进入了`view-mode’, 说明你正在浏览buffer, 或者是键入的字符要覆盖掉当前的字符, 这时候光标会由长条状变成方块状, 合情合理!
经过以上改进, 我们编辑, 定位光标都方便极了.
我加了一个小函数, 更方便的控制是否使用cursor-chg. 我增加的代码在这里, 内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | ;;; dired-lis.el --- Change cursor smartly ;; Copyright (C) 2009 ahei ;; Author: ahei <ahei0802@126.com> ;; Keywords: cursor ;; This file 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 file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; Change cursor smartly ;;; Installation: ;; ;; Copy cursor-change.el to your load-path and add following statement to ;; your .emacs: ;; ;; (require 'cursor-change) ;; ;; then M-x cursor-change-mode to use this library. ;;; History: ;; ;; 2009-11-22 ;; * initial version 1.0. ;;; Code: (require 'cursor-chg) (defgroup cursor-change nil "Group for cursor-change." :group 'cursor :prefix "cursor-change-") (defvar cursor-change-old-cursor-type nil "Cursor type before toggle on function `cursor-change-mode'.") (defvar cursor-change-old-blink-cursor-mode nil "`blink-cursor-mode' before toggle on function `crsor-change-mode'.") (setq curchg-default-cursor-color "green") ;;;###autoload (define-minor-mode cursor-change-mode "Toggle `cursor-change-mode'." :global t :group 'cursor-change (if cursor-change-mode (progn (setq cursor-change-old-cursor-type (cursor-change-get-cursor-type)) (setq cursor-change-old-blink-cursor-mode blink-cursor-mode)) (blink-cursor-mode (if cursor-change-old-blink-cursor-mode 1 -1))) (toggle-cursor-type-when-idle cursor-change-mode) (change-cursor-mode cursor-change-mode) (unless cursor-change-mode (curchg-set-cursor-type cursor-change-old-cursor-type))) (defun cursor-change-get-cursor-type (&optional frame) "Get cursor type of frame FRAME." (cdr (assq 'cursor-type (frame-parameters frame)))) (defun curchg-change-cursor-on-overwrite/read-only () "Set cursor type differently for overwrite mode, function `view-mode', and read-only buffer. That is, use one cursor type for overwrite mode and read-only buffers, and another cursor type otherwise." (curchg-set-cursor-type (if (or buffer-read-only overwrite-mode view-mode) curchg-overwrite/read-only-cursor-type curchg-default-cursor-type))) (provide 'cursor-change) ;;; cursor-change.el ends here |

GD Star Rating
loading...
标签:ahei, autoload, buffer, cursor, cursor-change, cursor-chg, DEA, Emacs, erc, IDE, lightbox, lisp, mode, org, screenshot, se, term, vi, 光标, 扩展, 配色, 配色loading...
你好 我想请你帮我个忙
我习惯在emacs下用vip-mode vi模式,挺方便
我想请你帮我做个功能,就是在vip-mode下 改变光标形状或者颜色,退出时再改回来
应该不难吧 谢谢了
[回复]
ahei 回复:
八月 21st, 2010 at 2:56 下午
你在它们的hook里面增加改变光标形状的代码就可以啦
[回复]
匿名 回复:
八月 23rd, 2010 at 4:27 上午
(add-hook ‘vip-mode-hook
这个不能用啊 不知道什么原因 能帮忙试一下么
[回复]
ahei 回复:
九月 12th, 2010 at 2:26 下午
@,
[回复]
匿名 回复:
八月 23rd, 2010 at 4:28 上午
@ahei,
(if (or buffer-read-only overwrite-mode view-mode vip-mode)
这样会出错的阿
[回复]
ahei 回复:
八月 23rd, 2010 at 5:49 上午
@, 我工作比较忙,有空帮你看看吧
[回复]
匿名 回复:
八月 23rd, 2010 at 8:58 上午
@ahei,
恩 打扰了 3Q 有空帮我看看吧
[回复]
用这个好像在光标滚到最下面或者最上面,开始进入下一页的时候,会有强烈的抖动…
不知道是我的个例还是都这样?
[回复]
ahei 回复:
八月 31st, 2010 at 9:05 下午
@jayklx, 没发现啊,是不是别的插件的原因?
[回复]
wgf4242 回复:
九月 12th, 2010 at 5:39 下午
@ahei,
;滚动页面时比较舒服,不要整页的滚动
(setq scroll-step 1
scroll-margin 3
scroll-conservatively 10000)
是这个么?
[回复]
ahei 回复:
九月 12th, 2010 at 8:34 下午
@wgf4242, 你去掉试试呗,我这没你说的情况
[回复]