注册 登录
编程论坛 Linux教室

A bug(?) in linum mode and my resolution

zklhp 发布于 2012-10-23 19:56, 1879 次点击
A bug(?) in linum mode and my resolution

;; Author: zklhp
;; QQ: 493165744  Email: zklhp*At*

When I use linum mode, I find that the left margin seems to be fixed even the text is scaled.

只有本站会员才能查看附件,请 登录


This seems to be a bug because in linum mode the width of left margin is decided like this.

(setq width (max width (length str)))

To solve this bug I prefer to defadvice linum-update-window. Here is my work.

程序代码:

(defadvice linum-update-window (after fix-scale-bugs (win) activate compile)
  "fix the bug when scale text"
  (interactive)
  (if (memq 'text-scale-mode minor-mode-list)
      (progn
    (let ((width (car (window-margins win))))
      (setq width (ceiling (* width (expt text-scale-mode-step text-scale-mode-amount))))
      (set-window-margins win width (cdr (window-margins win)))
      ;; (message "%d" width)
      )
    )
    )
  )


只有本站会员才能查看附件,请 登录


上面那个有warning 稍微改了下
程序代码:

(defadvice linum-update-window (after fix-scale-bugs (win) activate compile)
  "fix the bug when scale text"
  (interactive)
  (if (memq 'text-scale-mode minor-mode-list)
      (progn
    (let ((width (car (window-margins win))))
      (defvar text-scale-mode-step)
      (defvar text-scale-mode-amount)
      (setq width (ceiling (* width (expt text-scale-mode-step text-scale-mode-amount))))
      (set-window-margins win width (cdr (window-margins win)))
      )
    )
    )
  )





[ 本帖最后由 zklhp 于 2012-10-27 22:04 编辑 ]
6 回复
#2
madfrogme2012-10-23 20:13
原来如此,今天学了4招,试了一下,果然管用,版主威武
#3
zklhp2012-10-23 20:21
以下是引用madfrogme在2012-10-23 20:13:23的发言:

原来如此,今天学了4招,试了一下,果然管用,版主威武

举一反三 真是我们学习的榜样啊。。
#4
madfrogme2012-10-23 20:59
回复 3楼 zklhp
我的意思是上下左右 4招
#5
pangding2012-10-23 23:25
技术帖,加个亮吧。
#6
pangding2012-10-24 00:06
哦,说到 bug。我以前在 vim 里遇到一个:
在 .vimrc 里加一句
map <Esc>[    {
再用 vim(不是 gvim),一进去就会发现进入好像按了一下 c 键的感觉。大家可以试试。

我当时加这句是为了模拟 emacs 的段落上下移按键(虽然 emacs 的是 M-{ 吧)。emacs 有些移动键,用 alt 引导的,用惯了的话在 vim 的插入模式下用用还是比较方便的。
一开始试了 <M-[> 这么加映射,但好像不起作用。后来发现 <esc>[ 这么映射有效果,先 esc 再 [ 和 alt+[ 都能用,和 emacs 一样。还以为就可以这么映射呢。但加后来批量加了一些之后,发现出了问题,想知道是哪条的问题。
但用 debug 模式进 vim 就不会出现好像按了 c 的效果。无奈只好用逐条删的方式排查,发现的是这句。后来改成 <esc>{ 就相安无事了。但总觉得是 bug。

后来连自己查资料带请教人,才知道这个终端里的键映射是个复杂的主题。不是 vim 的自身的问题。vim 的手册里也有提,详见 :h terminal-info
我请教了高手,有人给了解决方案。不过后来我不用这个映射了,也就没仔细研究,现在也没搞得太清楚。

这个映射不是 vim 的 bug,但是比较有意思的是用 debug 模式进 vim 这个问题就不出了,这应该算 vim 的一个 bug 吧。
但是 vim 手册里有提有关 debug 模式,以及 vim-script 的调试工具都不尽完美,开发者一直都在努力这样的话,也不能求全择备。
毕竟 vim 和 emacs 的哲学就不一样,支持一个内置脚本本来就是一种附属功能(虽然现在这个功能已经很强大),而不是像 emacs,elisp 才是它的核心。
#7
有容就大2012-10-26 22:47
Here is my work.

So good work! Still recruit?




[ 本帖最后由 有容就大 于 2012-10-26 23:37 编辑 ]
1