From: Lars Ingebrigtsen Date: Wed, 27 Jan 2021 06:04:08 +0000 (+0100) Subject: Fix indentation in sieve-mode X-Git-Tag: emacs-28.0.90~4107 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9d50d7a0c6ff742ad682ef63e09c7e7341909b28;p=emacs.git Fix indentation in sieve-mode * lisp/net/sieve-mode.el (sieve-mode-indent-function): New function. (sieve-mode): Don't inherit from C mode, because the syntax doesn't really resemble C mode that much (except being curly braced). --- diff --git a/lisp/net/sieve-mode.el b/lisp/net/sieve-mode.el index fbc4e75fae5..7bc1d16122d 100644 --- a/lisp/net/sieve-mode.el +++ b/lisp/net/sieve-mode.el @@ -128,6 +128,9 @@ (modify-syntax-entry ?| "." st) (modify-syntax-entry ?_ "_" st) (modify-syntax-entry ?\' "\"" st) + (modify-syntax-entry ?\{ "(}" st) + (modify-syntax-entry ?\} "){" st) + (modify-syntax-entry ?\" "\"" st) st) "Syntax table in use in sieve-mode buffers.") @@ -178,12 +181,8 @@ 'syntax-table (string-to-syntax "|"))))) ;;;###autoload -(define-derived-mode sieve-mode c-mode "Sieve" +(define-derived-mode sieve-mode prog-mode "Sieve" "Major mode for editing Sieve code. -This is much like C mode except for the syntax of comments. Its keymap -inherits from C mode's and it has the same variables for customizing -indentation. It has its own abbrev table and its own syntax table. - Turning on Sieve mode runs `sieve-mode-hook'." (setq-local paragraph-start (concat "$\\|" page-delimiter)) (setq-local paragraph-separate paragraph-start) @@ -194,8 +193,17 @@ Turning on Sieve mode runs `sieve-mode-hook'." (setq-local syntax-propertize-function #'sieve-syntax-propertize) (setq-local font-lock-defaults '(sieve-font-lock-keywords nil nil ((?_ . "w")))) + (setq-local indent-line-function #'sieve-mode-indent-function) (easy-menu-add-item nil nil sieve-mode-menu)) +(defun sieve-mode-indent-function () + (save-excursion + (beginning-of-line) + (let ((depth (car (syntax-ppss)))) + (when (looking-at "[ \t]*}") + (setq depth (1- depth))) + (indent-line-to (* 2 depth))))) + (provide 'sieve-mode) ;; sieve-mode.el ends here