8

emacsのESS/Stataモードは、演算子で終わる行に続く行を誤ってインデントします。これらの行を複数行のコマンドとして誤って解釈しているようです。

例えば:

gen foo = 1

/* generate another variable */
  gen bar = 1

「genbar=1」という行はインデントしないでください。EMACSはコメントの末尾のスラッシュを演算子として解釈し、このコード行が2行にまたがっていると考えているようです。

実際、stataの複数行コマンドには3つの末尾のスラッシュがあり、3つの末尾のスラッシュがない改行はステートメントの終わりを示します。たとえば、次のインデントが正しいでしょう。

gen bar = 1
gen ///
  foo = 1

この動作を修正するために.emacsに入れることができるものはありますか?自動タブを完全に放棄したくありません。/*このように見えるコメントを除いて、すべてに対して非常にうまく機能します*/。

ありがとう、

Pnj

4

1 に答える 1

5

You're right, ESS interprets the trailing / as an indication of line continuation. This is hard-coded into the function ess-continued-statement-p, so to modify the behaviour you have to rewrite the code. The following code (in your .emacs) works for your examples.

(eval-after-load 'ess-mode
  '(defun ess-continued-statement-p ()
   "this is modified code"
     (let ((eol (point)))
       (save-excursion
         (cond ((memq (preceding-char) '(nil ?\, ?\; ?\} ?\{ ?\]))
                nil)
               ;; ((bolp))
               ((= (preceding-char) ?\))
                (forward-sexp -2)
                (looking-at "if\\b[ \t]*(\\|function\\b[ \t]*(\\|for\\b[ \t]*(\\|while\\b[ \t]*("))
               ((progn (forward-sexp -1)
                       (and (looking-at "else\\b\\|repeat\\b")
                            (not (looking-at "else\\s_\\|repeat\\s_"))))
                (skip-chars-backward " \t")
                (or (bolp)
                    (= (preceding-char) ?\;)))
               (t
                (progn (goto-char eol)
                       (skip-chars-backward " \t")
                       (or (and (> (current-column) 1)
                                (save-excursion (backward-char 1)

        ;;;; Modified code starts here: ;;;;
                                                (or (looking-at "[-:+*><=]")
                                                    (and (looking-at "/")
                                                         (save-excursion (backward-char 1)
                                                                         (not (looking-at "*")))))))
        ;;;; End of modified code ;;;;

                           (and (> (current-column) 3)
                                (progn (backward-char 3)
                                       (looking-at "%[^ \t]%")))))))))))
于 2011-11-16T14:30:58.280 に答える