X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=elisp%2Flilypond-indent.el;h=70d24f9b185bd3094033dea5e350299a832f7f35;hb=b5de1ca579bc679f69b5df30803fda31a74075d5;hp=4626646d06a7139dd40c96cb843cdf71dc8ceae9;hpb=5e738a5fbbccd3b1cf56976f103633109d584d3c;p=lilypond.git diff --git a/elisp/lilypond-indent.el b/elisp/lilypond-indent.el index 4626646d06..70d24f9b18 100644 --- a/elisp/lilypond-indent.el +++ b/elisp/lilypond-indent.el @@ -11,46 +11,68 @@ ;;; Variables for customising indentation style ;;; TODO: -;;; * currently, in bracket matching one may need a non-bracket +;;; * currently, in bracket matching one may need a non-bracket ;;; chararacter between the bracket characters, like ( ( ) ) -(defcustom LilyPond-indent-level 4 - "*Indentation of lilypond statements with respect to containing block.") +(defcustom LilyPond-indent-level 2 + "*Indentation of lilypond statements with respect to containing block." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-brace-offset 0 "*Extra indentation for open braces. -Compares with other text in same context.") +Compares with other text in same context." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-angle-offset 0 "*Extra indentation for open angled brackets. -Compares with other text in same context.") +Compares with other text in same context." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-square-offset 0 "*Extra indentation for open square brackets. -Compares with other text in same context.") +Compares with other text in same context." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-scheme-paren-offset 0 "*Extra indentation for open scheme parens. -Compares with other text in same context.") +Compares with other text in same context." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-close-brace-offset 0 - "*Extra indentation for closing braces.") + "*Extra indentation for closing braces." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-close-angle-offset 0 - "*Extra indentation for closing angle brackets.") + "*Extra indentation for closing angle brackets." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-close-square-offset 0 - "*Extra indentation for closing square brackets.") + "*Extra indentation for closing square brackets." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-close-scheme-paren-offset 0 - "*Extra indentation for closing scheme parens.") + "*Extra indentation for closing scheme parens." + :group 'LilyPond + :type 'integer) (defcustom LilyPond-fancy-comments t - "*Non-nil means distiguish between %, %%, and %%% for indentation.") + "*Non-nil means distiguish between %, %%, and %%% for indentation." + :group 'LilyPond + :type 'boolean) -(defcustom LilyPond-comment-region "%%$" +(defcustom LilyPond-comment-region "%%%" "*String inserted by \\[LilyPond-comment-region]\ - at start of each line in region.") + at start of each line in region." + :group 'LilyPond + :type 'string) (defun LilyPond-comment-region (beg-region end-region) "Comment/uncomment every line in the region. @@ -132,11 +154,11 @@ Returns nil if line starts inside a string" ;; start there too. If LilyPond-indent-level is zero, use ;; LilyPond-brace-offset instead (+ (if (and (bolp) (zerop LilyPond-indent-level)) - (cond ((= (following-char) ?{) + (cond ((= (following-char) ?{) LilyPond-brace-offset) - ((= (following-char) ?<) + ((= (following-char) ?<) LilyPond-angle-offset) - ((= (following-char) ?[) + ((= (following-char) ?\[) LilyPond-square-offset) ((= (following-char) ?\)) LilyPond-scheme-paren-offset) @@ -174,7 +196,7 @@ Return the amount the indentation changed by." (setq indent (+ indent (- LilyPond-close-brace-offset LilyPond-indent-level)))) ((= (following-char) ?>) (setq indent (+ indent (- LilyPond-close-angle-offset LilyPond-indent-level)))) - ((= (following-char) ?]) + ((= (following-char) ?\]) (setq indent (+ indent (- LilyPond-close-square-offset LilyPond-indent-level)))) ((and (= (following-char) ?\)) (LilyPond-inside-scheme-p)) (setq indent (+ indent (- LilyPond-close-scheme-paren-offset LilyPond-indent-level)))) @@ -182,7 +204,7 @@ Return the amount the indentation changed by." (setq indent (+ indent LilyPond-brace-offset))) ((= (following-char) ?<) (setq indent (+ indent LilyPond-angle-offset))) - ((= (following-char) ?[) + ((= (following-char) ?\[) (setq indent (+ indent LilyPond-square-offset))) ((and (= (following-char) ?\() (LilyPond-inside-scheme-p)) (setq indent (+ indent LilyPond-scheme-paren-offset))) @@ -304,7 +326,7 @@ Argument LIM limit." ;; duh .. a single '>', as in chords '<< ... >>', was not matched here ( ?} . ("{" . "}")) ;; ligatures '\[ ... \]' are skipped in the following expression - ( ?] . ("\\([^\\]\\([\\][\\]\\)*\\|^\\)[[]" . "\\([^\\]\\([\\][\\]\\)*\\|^\\)[]]")) + ( ?\] . ("\\([^\\]\\([\\][\\]\\)*\\|^\\)[[]" . "\\([^\\]\\([\\][\\]\\)*\\|^\\)[]]")) ( "\\]" . ("\\([^\\]\\|^\\)\\([\\][\\]\\)*[\\][[]" . "\\([^\\]\\|^\\)\\([\\][\\]\\)*[\\][]]")) ( "\\)" . ("\\([^\\]\\|^\\)\\([\\][\\]\\)*[\\][(]" . "\\([^\\]\\|^\\)\\([\\][\\]\\)*[\\][)]")) )) @@ -313,7 +335,7 @@ Argument LIM limit." (defconst LilyPond-parens-alist `( ( ?< . ?> ) ( ?{ . ?} ) - ( ?[ . ?] ) + ( ?\[ . ?\] ) ( "\\[" . "\\]" ) ( ?\( . ?\) ) ( "\\(" . "\\)" ) @@ -361,7 +383,7 @@ slur-paren-p defaults to nil. ;; match concurrent one-char opening and closing slurs (if (and (eq dir 1) (not (sequencep bracket-type)) - (eq (char-syntax (char-after oldpos)) ?\() + (eq (char-syntax (or (char-after oldpos) 0)) ?\() (not (eq (char-after oldpos) ?<))) ;; anyway do not count open slur, since already level = -1 (progn (forward-char 1) @@ -384,7 +406,7 @@ slur-paren-p defaults to nil. (if (not (save-excursion (goto-char (match-end 0)) ;; skip over strings and comments (LilyPond-inside-string-or-comment-p))) - (if (memq match '(?} ?> ?] ?\))) + (if (memq match '(?} ?> ?\] ?\))) ;; count closing brackets (progn (setq level (1+ level)) ;; slurs may be close to each other, e.g., @@ -430,17 +452,16 @@ slur-paren-p defaults to nil. (let ( (test-point (point)) (level 0) ) (save-excursion - (if (or (and (/= (point) (point-max)) - (= (char-after (point)) ?\() - (or (= (char-after (- (point) 1)) ?#) - (and (= (char-after (- (point) 2)) ?#) - (= (char-after (- (point) 1)) ?`)))) - (and (re-search-backward "#(\\|#`(" nil t) + (if (or (and (eq (char-after (point)) ?\() + (save-excursion + (skip-chars-backward "'`") + (memq (char-before) '(?# ?$)))) + (and (re-search-backward "[#$][`']?(" nil t) (progn (search-forward "(") (setq level 1) (while (and (> level 0) - (re-search-forward "(\\|)" test-point t) + (re-search-forward "[()]" test-point t) (setq match (char-after (match-beginning 0))) (<= (point) test-point)) (if (= match ?\() @@ -470,7 +491,7 @@ builtin 'blink-matching-open' is not used. In syntax table, see ;; Test if a ligature \] or expressional slur \) was encountered (setq bracket-type (char-after (point))) (setq char-before-bracket-type nil) - (if (memq bracket-type '(?] ?\) ?[ ?\()) + (if (memq bracket-type '(?\] ?\) ?\[ ?\()) (progn (setq np -1) (while (eq (char-before (- (point) (setq np (+ np 1)))) ?\\)