From a802a6c823f7101ab10f9e060a4fdac5c5ffc170 Mon Sep 17 00:00:00 2001 From: Fanael Linithien Date: Wed, 5 Nov 2014 20:54:50 +0100 Subject: [PATCH] Refactor the code, no functional changes. Use cond instead of unless + if to reduce indentation, extract a common subexpression to a variable, introduce a variable so a multiline function call can be written in a single line. --- rainbow-delimiters.el | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el index 6be845f..8374074 100644 --- a/rainbow-delimiters.el +++ b/rainbow-delimiters.el @@ -229,22 +229,20 @@ Used by font-lock for dynamic highlighting." (setq ppss (save-excursion (parse-partial-sexp last-ppss-pos delim-pos nil nil ppss))) (setq last-ppss-pos delim-pos) - (unless (rainbow-delimiters--char-ineligible-p delim-pos ppss (car delim-syntax)) - (if (= 4 (logand #xFFFF (car delim-syntax))) - (progn - (setq depth (1+ depth)) - (rainbow-delimiters--apply-color delim-pos - depth - t)) + (let ((delim-syntax-code (car delim-syntax))) + (cond + ((rainbow-delimiters--char-ineligible-p delim-pos ppss delim-syntax-code) + nil) + ((= 4 (logand #xFFFF delim-syntax-code)) + (setq depth (1+ depth)) + (rainbow-delimiters--apply-color delim-pos depth t)) + (t ;; Not an opening delimiter, so it's a closing delimiter. - (let ((matching-opening-delim (char-after (nth 1 ppss)))) - (rainbow-delimiters--apply-color delim-pos - depth - (eq (cdr delim-syntax) - matching-opening-delim)) + (let ((matches-p (eq (cdr delim-syntax) (char-after (nth 1 ppss))))) + (rainbow-delimiters--apply-color delim-pos depth matches-p) ;; Don't let `depth' go negative, even if there's an unmatched ;; delimiter. - (setq depth (max 0 (1- depth))))))))) + (setq depth (max 0 (1- depth)))))))))) ;; We already fontified the delimiters, tell font-lock there's nothing more ;; to do. nil)