Faça o emacs mostrar comentários depois de} else {

2

Isso é melhor descrito em um exemplo. Digamos que você tenha o seguinte arquivo de origem C:

if (something is true)
{
  meh();
} else if (something else is true) {
  foo();
} else { // something even different must be true
  bar();
}

Agora, no emacs, quando você digita o último } , ele diz Matches } else { .

Como posso dizer a linha inteira, ou seja. Matches } else { // something even different must be true ?

Obrigado antecipadamente.

    
por houbysoft 30.08.2010 / 02:15

2 respostas

2

Essa alteração para 'blink-matching-open faz o que você deseja. Eu o renomei para 'my-blink-matching-open para que você não perca o original. Seguir a definição é a configuração que faz com que essa rotina tenha efeito.

(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)
    
por 30.08.2010 / 04:27
1

Eu não tenho muita experiência com o emacs, então não sei se isso funcionaria, mas acho que vale a pena tentar: tente colocar o comentário entre o else e a chave:

} else /* something even different must be true */ {
    
por 30.08.2010 / 03:25

Tags