;;; lilypond-indent.el --- Auto-indentation for lilypond code
;;;
;;; Heikki Junes <hjunes@cc.hut.fi>
-;;; * redefine Emacs' show-paren-function and XEmacs' paren-highlight
+;;; * introduce Lilypond-show-paren-function for Emacs and
+;;; Lilypond-paren-highlight for XEmacs
;;; * match two-char slurs '\( ... \)' and '\[ ... \]' separately.
+;;; * adopt Emacs' f90-comment-region
;;; Chris Jackson <chris@fluffhouse.org.uk>
;;; some code is taken from ESS (Emacs Speaks Statistics) S-mode by A.J.Rossini <rossini@biostat.washington.edu>
;;; * in syntax-highlighting slurs are not always highlighted the right way
;;; e.g. opening slurs are found found better in "#( ( ) ( ) )" than
;;; opening slurs
+;;; * Mouse double-clicks should use LilyPond-scan-sexps for slur matching.
(defcustom LilyPond-indent-level 4
"*Indentation of lilypond statements with respect to containing block.")
(defcustom LilyPond-fancy-comments t
"*Non-nil means distiguish between %, %%, and %%% for indentation.")
+(defcustom LilyPond-comment-region "%%$"
+ "*String inserted by \\[LilyPond-comment-region]\
+ at start of each line in region.")
+
+(defun LilyPond-comment-region (beg-region end-region)
+ "Comment/uncomment every line in the region.
+Insert LilyPond-comment-region at the beginning of every line in the region
+or, if already present, remove it."
+ (interactive "*r")
+ (let ((end (make-marker)))
+ (set-marker end end-region)
+ (goto-char beg-region)
+ (beginning-of-line)
+ (if (looking-at (regexp-quote LilyPond-comment-region))
+ (delete-region (point) (match-end 0))
+ (insert LilyPond-comment-region))
+ (while (and (zerop (forward-line 1))
+ (< (point) (marker-position end)))
+ (if (looking-at (regexp-quote LilyPond-comment-region))
+ (delete-region (point) (match-end 0))
+ (insert LilyPond-comment-region)))
+ (set-marker end nil)))
(defun LilyPond-calculate-indent ()
"Return appropriate indentation for current line as lilypond code.
(current-indentation)))))))))
-
(defun LilyPond-indent-line ()
"Indent current line as lilypond code.
Return the amount the indentation changed by."
;; 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 (char-after oldpos)) ?\()
+ (not (eq (char-after oldpos) ?<)))
;; anyway do not count open slur, since already level = -1
(progn (forward-char 1)
(if (eq (following-char)
(LilyPond-blink-matching-paren)
(forward-char 1))))))
-;;; REDEFINITIONS
-(defun scan-sexps (pos dir)
+(defun LilyPond-scan-sexps (pos dir)
"This function is redefined to be used in Emacs' show-paren-function and
in XEmacs' paren-highlight."
(LilyPond-blink-matching-paren dir))
-
-;; Emacs and XEmacs have slightly different names for parenthesis highlighting.
-(if (not (string-match "XEmacs\\|Lucid" emacs-version))
- (progn
- (fset 'old-show-paren-function (symbol-function 'show-paren-function))
- (defun show-paren-function ()
- "Highlights the matching slur if cursor is moved before opening or
-after closing slur. In this redefinition strings and comments are skipped."
- (if (not (LilyPond-inside-string-or-comment-p))
- (old-show-paren-function))))
- (progn
- ;; NOTE: paren-set-mode must be set before paren-highlight is redefined
- (paren-set-mode 'paren)
- (fset 'old-paren-highlight (symbol-function 'paren-highlight))
- (defun paren-highlight ()
- "Highlights the matching slur if cursor is moved before opening or
-after closing slur. In this redefinition strings and comments are skipped."
- (if (not (LilyPond-inside-string-or-comment-p))
- (old-paren-highlight)))))