Created
May 26, 2020 15:54
-
-
Save gengar/e4d6df83fb10980816eb798bcc2ac56f to your computer and use it in GitHub Desktop.
c++-modeがfunction-try-blockのインデントでおかしいのをadviceで修正する試み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; c-beginning-of-statement-1 は function-try-block のとき、 | |
;; (1) メンバ初期化があれば、最初のメンバ初期化の先頭 | |
;; (2) さもなくば、 try の先頭 | |
;; まで point が動く。try の先頭位置から再び c-beginning-of-statement-1 すると期待する場所へ動く。 | |
(defun my:c-beginning-of-statement-1 (orig &rest args) | |
(let* ((ret (apply orig args)) | |
(try-pos (and (eq 'c++-mode major-mode) | |
(save-excursion | |
(or (and (looking-at-p "try") | |
(point)) | |
(and (progn | |
(c-backward-token-2) | |
(= ?: (char-after))) | |
(progn | |
(c-backward-token-2) | |
(looking-at-p "try")) | |
(point))))))) | |
(if try-pos | |
(progn | |
(goto-char try-pos) | |
(apply orig args)) | |
ret))) | |
(advice-add #'c-beginning-of-statement-1 | |
:around | |
#'my:c-beginning-of-statement-1) | |
;; c-just-after-func-arglist-p は function-try-block のとき、 | |
;; try の先頭で止まり nil を返す。 | |
;; try の前から再び c-just-after-func-arglist-p すると期待する結果が得られるが point は try の手前になるので、これを読み飛ばす。 | |
(defun my:c-just-after-func-arglist-p (orig &optional limit) | |
(let ((result (funcall orig limit))) | |
(if (eq 'c++-mode major-mode) | |
(or result | |
(and (looking-at-p "try") | |
(funcall orig limit) | |
(progn | |
(c-forward-token-2) | |
t))) | |
result))) | |
(advice-add #'c-just-after-func-arglist-p | |
:around | |
#'my:c-just-after-func-arglist-p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment