]> git.donarmstrong.com Git - lilypond.git/commitdiff
Move all paren matching to lilypond-indent.el
authorHeikki Junes <heikki.junes@hut.fi>
Tue, 20 May 2003 21:16:11 +0000 (21:16 +0000)
committerHeikki Junes <heikki.junes@hut.fi>
Tue, 20 May 2003 21:16:11 +0000 (21:16 +0000)
ChangeLog
lilypond-font-lock.el
lilypond-indent.el
lilypond-mode.el

index 7e01325158204913e28b4cd54b89955c10b454ae..65ede91751386925b881093389e539533a030ba8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-05-21  Heikki Junes  <hjunes@cc.hut.fi>
+
+       * lilypond-mode.el,
+       lilypond-font-lock.el,
+       lilypond-indent.el: Move all paren matching to lilypond-indent.el.
+
 2003-05-20  Heikki Junes  <hjunes@cc.hut.fi>
 
        * lilypond-mode.el: Remove outdated code. Stress the difference 
index 7c376556325bdc795134db088f06a107b0bfb8ff..3212867a9a60dd15f21e55abaca1cf4239b211a8 100644 (file)
           (lambda (x) (modify-syntax-entry
                        (car x) (cdr x) LilyPond-mode-syntax-table)))
          '(
-           ;; also '['- and ']'-slurs should be handled by lilypond-indent.el
-           ;; in order to match also '\['- and '\]'-slurs in ligatures
-           ( ?\[ . "(]" ) ( ?\] . ")[" ) ; handled by the syntax table
-           ;; all the other paren characters are now handled by   
+           ;; also '['- and ']'-slurs are handled by lilypond-indent.el
+           ;( ?\[ . "(]" ) ( ?\] . ")[" )
+           ;; all the paren characters are now handled by   
            ;; lily-specific indenting/matching code in lilypond-indent.el 
+           ( ?\[ . "." ) ( ?\] . "." )
            ( ?\( . "." ) ( ?\) . "." ) 
-           ( ?\< . "." )( ?\> . ".") 
+           ( ?\< . "." ) ( ?\> . ".") 
            ( ?\{  .  ". 2" )  ; also 2nd char in begin of block-comment
            ( ?\}  .  ". 4" )  ; also 2nd char in end of block-comment
            ( ?\%  .  "< 13" ) ; comment starter, 1st char in block-comments
index 73c4a2aff384fe0288624ae0ecefe200093e86d5..a0bb8df163477368da5ac20267e2c6c8026ad9fa 100644 (file)
@@ -6,10 +6,11 @@
 ;;; Variables for customising indentation style
 
 ;;; TODO:
-;;;    * emulate show-paren-mode 
+;;;    * emulate show-paren-mode, i.e., highlight the matching bracket if
+;;;      - the cursor is on the matching opening bracket
+;;;      - the cursor is after the matching closing bracket
 ;;;    * separate '('- and ')'-slurs from '\('- and '\)'-slurs.
-;;;    * include '['- and ']'-slurs from syntax table 
-;;;      in order to match also '\['- and '\]'-slurs in ligatures
+;;;    * separate '['- and ']'-slurs from '\['- and '\]'-slurs.
 
 (defcustom LilyPond-indent-level 4
   "*Indentation of lilypond statements with respect to containing block.")
@@ -22,6 +23,10 @@ Compares with other text in same context.")
   "*Extra indentation for open angled brackets .
 Compares with other text in same context.")
 
+(defcustom LilyPond-square-offset 0
+  "*Extra indentation for open square brackets .
+Compares with other text in same context.")
+
 (defcustom LilyPond-scheme-paren-offset 0
   "*Extra indentation for open scheme parens .
 Compares with other text in same context.")
@@ -32,6 +37,9 @@ Compares with other text in same context.")
 (defcustom LilyPond-close-angle-offset 0
   "*Extra indentation for closing angle brackets.")
 
+(defcustom LilyPond-close-square-offset 0
+  "*Extra indentation for closing square brackets.")
+
 (defcustom LilyPond-close-scheme-paren-offset 0
   "*Extra indentation for closing scheme parens.")
 
@@ -104,6 +112,8 @@ Returns nil if line starts inside a string"
                            LilyPond-brace-offset)
                           ((= (following-char) ?<) 
                            LilyPond-angle-offset)
+                          ((= (following-char) ?[) 
+                           LilyPond-square-offset)
                           ((= (following-char) ?\))
                            LilyPond-scheme-paren-offset)
                           (t
@@ -141,12 +151,16 @@ 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) ?])
+              (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))))
              ((= (following-char) ?{)
               (setq indent  (+ indent LilyPond-brace-offset)))
              ((= (following-char) ?<)
               (setq indent  (+ indent LilyPond-angle-offset)))
+             ((= (following-char) ?[)
+              (setq indent  (+ indent LilyPond-square-offset)))
              ((and (= (following-char) ?\() (LilyPond-inside-scheme-p))
               (setq indent  (+ indent LilyPond-scheme-paren-offset)))
              ))))
@@ -256,9 +270,8 @@ Argument LIM limit."
 
 
 ;; Key:   Type of bracket (character). 
-;; Value: Pair of regexps representing the corresponding open and close bracket"
-;; () are treated specially (need to indent in Scheme but not in music), and []
-;; are handled by the syntax table
+;; Value: Pair of regexps representing the corresponding open and close bracket
+;; () are treated specially (need to indent in Scheme but not in music)
 
 (defconst LilyPond-parens-regexp-alist
   `( ( ?>  .  ("\\([^\\]\\|^\\)<" . "[^ \\n\\t_^-]\\s-*>\\|[_^-]\\s-*[-^]\\s-*>"))
@@ -266,12 +279,14 @@ Argument LIM limit."
      ;; but a b c^-> and a b c^^> are close brackets with tenuto/marcato before them
      ;; also \> and \< are hairpins
      ( ?}  .  ("{" . "}"))
+     ( ?]  .  ("[[]" . "[]]"))
      ))
 
 
 (defconst LilyPond-parens-alist
   `( ( ?<  .  ?> )    
      ( ?{  .  ?} )    
+     ( ?[  .  ?] )
      ( ?\(  .  ?\) )
      ))
 
@@ -316,14 +331,14 @@ slur-paren-p defaults to nil.
                (setq match (char-before (match-end 0))))
       (if (not (save-excursion (goto-char (match-end 0)) 
                               (LilyPond-inside-string-or-comment-p)))
-         (if (memq match '(?} ?> ?\)))
+         (if (memq match '(?} ?> ?] ?\)))
              (progn (setq level (1+ level))
                     (if (and (= match ?>) 
-                             (looking-at ".\\s-+>\\|\\({\\|}\\|<\\|>\\|(\\|)\\)>"))
+                             (looking-at ".\\s-+>\\|\\({\\|}\\|<\\|>\\|(\\|)\\|[][]\\)>"))
                         (forward-char 1)))
            (progn (setq level (1- level))
                   (if (and (= match ?<)
-                           (looking-at ".\\s-+<\\|\\({\\|}\\|<\\|>\\|(\\|)\\)<"))
+                           (looking-at ".\\s-+<\\|\\({\\|}\\|<\\|>\\|(\\|)\\|[][]\\)<"))
                       (forward-char 1))))))
     (if (looking-at ".<\\|.>") (forward-char 1))
     (if (= level 0) 
@@ -378,8 +393,8 @@ the syntax table"
          (narrow-to-region (max (point-min)
                                 (- (point) blink-matching-paren-distance))
                            oldpos)))
-    (if (memq bracket-type '(?> ?}))
-       ;; < { need to be mutually balanced and nested, so search backwards for both of these bracket types 
+    (if (memq bracket-type '(?> ?} ?]))
+       ;; < { need to be mutually balanced and nested, so search backwards for both of these bracket types 
        (LilyPond-beginning-of-containing-sexp nil nil)  
       ;; whereas ( ) slurs within music don't, so only need to search for ( )
       (LilyPond-beginning-of-containing-sexp bracket-type t))
@@ -431,7 +446,7 @@ the syntax table"
 
 
 (defun LilyPond-electric-close-paren ()
-  "Blink on the matching open paren when a > or ) is inserted"
+  "Blink on the matching open paren when a >, ), } or ] is inserted"
   (interactive)
   (let ((oldpos (point)))
     (self-insert-command 1)
index 228a59868b9552dac05576015d7af34f68631116..e8a572d6fe8ee08cf95508c1060410c376cf6073 100644 (file)
@@ -691,6 +691,7 @@ command."
   (define-key LilyPond-mode-map ")" 'LilyPond-electric-close-paren)
   (define-key LilyPond-mode-map ">" 'LilyPond-electric-close-paren)
   (define-key LilyPond-mode-map "}" 'LilyPond-electric-close-paren)
+  (define-key LilyPond-mode-map "]" 'LilyPond-electric-close-paren)
   (if (string-match "XEmacs\\|Lucid" emacs-version)
       (define-key LilyPond-mode-map [iso-left-tab] 'LilyPond-autocompletion)
     (define-key LilyPond-mode-map [iso-lefttab] 'LilyPond-autocompletion))