在 } { 之后,让emacs显示注释

分享于 

5分钟阅读

电脑

 

问题:

最好在一个例子中描述。 假设你有以下C 源 file:


if (something is true)


{


 meh();


} else if (something else is true) {


 foo();


} else {//something even different must be true


 bar();


}



现在在emacs中,当你输入最后一个 } 时, Matches } else {

我怎么能让它说整行,IE。 Matches } else {//something even different must be true

先谢谢了。


回答 1:

'blink-matching-open的更改完成你想要的。 我把它改名为 'my-blink-matching-open 这样你就不会丢失原来的。 根据定义,这个设置使这个例程生效。


(defun my-blink-matching-open ()


"Move cursor momentarily to the beginning of the sexp before point."


 (interactive)


 (when (and (> (point) (point-min))


 blink-matching-paren


 ;; Verify an even number of quoting characters precede the close.


 (= 1 (logand 1 (- (point)


 (save-excursion


 (forward-char -1)


 (skip-syntax-backward"/")


 (point))))))


 (let* ((oldpos (point))


 (message-log-max nil) ; Don't log messages about paren matching.


 (atdollar (eq (syntax-class (syntax-after (1- oldpos))) 8))


 (isdollar)


 (blinkpos


 (save-excursion


 (save-restriction


 (if blink-matching-paren-distance


 (narrow-to-region


 (max (minibuffer-prompt-end) ;(point-min) unless minibuf.


 (- (point) blink-matching-paren-distance))


 oldpos))


 (let ((parse-sexp-ignore-comments


 (and parse-sexp-ignore-comments


 (not blink-matching-paren-dont-ignore-comments))))


 (condition-case ()


 (scan-sexps oldpos -1)


 (error nil))))))


 (matching-paren


 (and blinkpos


 ;; Not syntax '$'.


 (not (setq isdollar


 (eq (syntax-class (syntax-after blinkpos)) 8)))


 (let ((syntax (syntax-after blinkpos)))


 (and (consp syntax)


 (eq (syntax-class syntax) 4)


 (cdr syntax))))))


 (cond


 ;; isdollar is for:


 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00871.html


 ((not (or (and isdollar blinkpos)


 (and atdollar (not blinkpos)) ; see below


 (eq matching-paren (char-before oldpos))


 ;; The cdr might hold a new paren-class info rather than


 ;; a matching-char info, in which case the two CDRs


 ;; should match.


 (eq matching-paren (cdr (syntax-after (1- oldpos))))))


 (if (minibufferp)


 (minibuffer-message" [Mismatched parentheses]")


 (message"Mismatched parentheses")))


 ((not blinkpos)


 (or blink-matching-paren-distance


 ;; Don't complain when `$' with no blinkpos, because it


 ;; could just be the first one typed in the buffer.


 atdollar


 (if (minibufferp)


 (minibuffer-message" [Unmatched parenthesis]")


 (message"Unmatched parenthesis"))))


 ((pos-visible-in-window-p blinkpos)


 ;; Matching open within window, temporarily move to blinkpos but only


 ;; if `blink-matching-paren-on-screen' is non-nil.


 (and blink-matching-paren-on-screen


 (not show-paren-mode)


 (save-excursion


 (goto-char blinkpos)


 (sit-for blink-matching-delay))))


 (t


 (save-excursion


 (goto-char blinkpos)


 (let ((open-paren-line-string


 (cond


 ;; When there's something following the brace


 ;; show the entire line


 ((save-excursion


 (forward-char 1)


 (skip-chars-forward" t")


 (not (eolp)))


 (buffer-substring (line-beginning-position)


 (line-end-position)))


 ;; Otherwise show the previous nonblank line,


 ;; if there is one.


 ((save-excursion (skip-chars-backward"n t") (not (bobp)))


 (concat


 (buffer-substring (progn


 (skip-chars-backward"n t")


 (line-beginning-position))


 (progn (end-of-line)


 (skip-chars-backward" t")


 (point)))


 ;; Replace the newline and other whitespace with `...'.


"..."


 (buffer-substring blinkpos (1+ blinkpos))))


 ;; There is nothing to show except the char itself.


 (t (buffer-substring blinkpos (1+ blinkpos))))))


 (message"Matches %s"


 (substring-no-properties open-paren-line-string)))))))))



(setq blink-paren-function 'my-blink-matching-open)




回答 2:

我对emacs没有很多经验,所以我不知道这是否能工作,但我认为这一点值得一试: 尝试在其他和大括号之间放置注释:


} else/* something even different must be true */{





COM  COMM  MAKE  显示  Emacs  comment  
相关文章