在php模式下,我尝试了catch(当它是全局的 - 没有功能时)
try {
throw new Exception("Hello");
} catch(Exception $e) {
}
缩进放了两个空格(甚至缩进是4个空格),我有一个用它修复它的函数:
(defun unindent-closure ()
(message "%s" c-syntactic-context) ; debug
(let ((syntax (mapcar 'car c-syntactic-context)))
(if (and (member 'arglist-cont-nonempty syntax)
(or
(member 'statement-block-intro syntax)
(member 'brace-list-intro syntax)
(member 'brace-list-close syntax)
(member 'block-close syntax)))
(save-excursion
(beginning-of-line)
(delete-char (* (count 'arglist-cont-nonempty syntax)
c-basic-offset)))
(if (member 'defun-close syntax)
(save-excursion
(beginning-of-line)
;; top level try cache have two extra spaces before closing braces
(if (looking-at "^ \\{2\\}[^ ]")
(progn
(beginning-of-line)
(delete-char 2))))))))
(add-hook 'php-mode-hook (lambda ()
(add-hook 'c-special-indent-hook 'unindent-closure)))
它还修复了闭包缩进,当我有4个空格作为缩进时它工作正常但是当我有2个空格时失败:
class foo extends Controler {
function foo() {
}
}
在这两种情况下,语法都是defun-close
(在结束卷曲时)。还有其他方法可以在php模式下修复try catch中的2个空格吗?