Emacs:当光标为ON时,匹配括号 [英] Emacs: Matching parenthesis when cursor is ON closing parenthesis

查看:219
本文介绍了Emacs:当光标为ON时,匹配括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{以前被问过: Emacs:当光标在它上面时突出显示匹配括号,而不是之后,但没有一个答案令人满意}

{It has been asked before: Emacs: highlight matching paren when cursor is on it, not after it but none of the answers are satisfactory}

我正在使用mic-paren以下.emacs设置(尽管所有类似的emacs包都存在问题,所以似乎是某种默认emacs的行为)

I am using mic-paren with following .emacs settings (although the problem exists with all similar emacs packages, so it seems to be some kind of default emacs behavior)

    (paren-activate)
    (setq paren-match-face 'highlight)
    (setq paren-sexp-mode t)

其中突出显示两个括号之间的所有文本。当光标开启圆括号但是从另一边开始,我必须将光标放在右括弧后,它的效果很好。当与粘液一起使用时,会导致奇怪的行为(这需要将光标放在右括号上以显示常规使用信息等)。有没有办法改变这种行为,并且当光标处于闭括号时使emacs与括号相匹配?

which highlight the all the text between two parenthesis. It works well when the cursor is ON opening parenthesis but from the other side, I have to put my cursor AFTER the closing parenthesis. This results in strange behavior when used with slime (which requires the cursor to be put ON the closing parenthesis to display general usage information and such). Is there any way to change this behavior and make emacs match parenthesis when the cursor is ON closing parenthesis?

编辑:次要语法修复

推荐答案

以下内容适用于mic-paren。但是,它有一些余辉;-)。如果光标位于关闭分隔符或其后面,则打开分隔符将被突出显示。

The following works for `mic-paren'. But, it has some afterglow;-). The opening delimiter is highlighted if the cursor is on the closing delimiter or just behind it.

(defadvice mic-paren-highlight (around cursorOnClosing activate)
  "Dirty hack to highlight sexps with closing delim below cursor"
  (if (eq (char-syntax (following-char)) ?\) )
      (let ((paren-priority 'close))
        (save-excursion
          (forward-char)
          ad-do-it))
    ad-do-it))

自然,为了使这项工作,您需要安装 mic -paren 正确。只需按照 mic-paren.el 中的安装指南:

Naturally, to make this work you need to install mic-paren correctly. Just follow the installation guide in mic-paren.el cited here:

安装:


  • 将此文件放在'load-path和byte-compile
    中的目录中。您可以肯定地忽略这些警告。

  • 将以下内容放在.emacs文件中:
    (GNU Emacs仅在窗口系统中支持mic-paren,但XEmacs
    支持mic-paren也没有X)

   (when (or (featurep 'xemacs) window-system)
      (require 'mic-paren) ; loading
      (paren-activate)     ; activating
   ; set here any of the customizable variables of mic-paren:
   ; ...
   )




  • 重新启动Emacs。现在安装并激活了mic-paren!

  • 要列出可能的自定义项,请输入 Ch f paren-activate'或
    转到自定义组 mic-paren-matching'。

  • EDITS:


    • 遵循Stefan关于(featurep'xemacs)的提示

    • follow Stefan's hint about (featurep 'xemacs)

    这篇关于Emacs:当光标为ON时,匹配括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆