]> git.donarmstrong.com Git - lilypond.git/blobdiff - lilypond-mode.el
polish.
[lilypond.git] / lilypond-mode.el
index 26df4e5ad774c1e9805adc927247f67d2394c6a8..ca5b3beed6717b9881a32d37b393c415c97cbd83 100644 (file)
@@ -22,7 +22,7 @@
 (require 'easymenu)
 (require 'compile)
 
-(defconst LilyPond-version "1.7.21"
+(defconst LilyPond-version "1.7.25"
   "`LilyPond-mode' version number.")
 
 (defconst LilyPond-help-address "bug-lilypond@gnu.org"
   '(("\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
   "Regexp used to match LilyPond errors.  See `compilation-error-regexp-alist'.")
 
+(defvar LilyPond-imenu nil
+  "A flag to tell whether LilyPond-imenu is turned on.")
+(make-variable-buffer-local 'LilyPond-imenu)
+
 (defcustom LilyPond-include-path ".:/tmp"
   "* LilyPond include path."
   :type 'string
@@ -513,12 +517,6 @@ Must be the car of an entry in `LilyPond-command-alist'."
   (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file)
 )
 
-;;; Refer to syntax-table (in lilypond-font-lock.el) for comment characters.
-(defun LilyPond-un-comment-region (start end level)
-  "Remove up to LEVEL comment characters from each line in the region."
-  (interactive "*r\np") 
-  (comment-region start end (- level)))
-
 ;; FIXME, this is broken
 (defun LilyPond-region-file (begin end)
   (let (
@@ -686,8 +684,7 @@ command."
   (define-key LilyPond-mode-map "\C-ci" 'LilyPond-quick-note-insert)
   (define-key LilyPond-mode-map "\C-cn" 'LilyPond-insert-tag-notes)
   (define-key LilyPond-mode-map "\C-cs" 'LilyPond-insert-tag-score)
-  (define-key LilyPond-mode-map "\C-c:" 'LilyPond-un-comment-region)
-  (define-key LilyPond-mode-map "\C-c;" 'comment-region)
+  (define-key LilyPond-mode-map "\C-c;" 'LilyPond-comment-region)
   (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)
@@ -999,9 +996,9 @@ command."
             ["Autocompletion"   LilyPond-autocompletion t]
             ))
          '(("Miscellaneous"
-            ["Uncomment Region" LilyPond-un-comment-region t]
-            ["Comment Region" comment-region t]
+            ["(Un)comment Region" LilyPond-comment-region t]
             ["Refontify buffer" font-lock-fontify-buffer t]
+            ["Add index menu" LilyPond-add-imenu-menu]
             ))
          '(("Info"
             ["LilyPond" LilyPond-info t]
@@ -1044,6 +1041,17 @@ command."
                 (LilyPond-command-region (mark t) (point))))
       (funcall LilyPond-command-current))))
 
+(defun LilyPond-add-imenu-menu ()
+  (interactive)
+  "Add an imenu menu to the menubar."
+  (if (not LilyPond-imenu)
+      (progn
+       (imenu-add-to-menubar "Index")
+       (redraw-frame (selected-frame))
+       (setq LilyPond-imenu t))
+    (message "%s" "LilyPond-imenu already exists.")))
+(put 'LilyPond-add-imenu-menu 'menu-enable '(not LilyPond-imenu))
+
 (defun LilyPond-mode ()
   "Major mode for editing LilyPond music files.
 
@@ -1097,33 +1105,16 @@ LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
   (make-local-variable 'indent-line-function)
   (setq indent-line-function 'LilyPond-indent-line)
 
-  (set-syntax-table LilyPond-mode-syntax-table)
+  (LilyPond-mode-set-syntax-table '(?\< ?\> ?\{ ?\}))
   (setq major-mode 'LilyPond-mode)
   (setq mode-name "LilyPond")
   (setq local-abbrev-table LilyPond-mode-abbrev-table)
   (use-local-map LilyPond-mode-map)
 
-  ;; In Emacs blink-...-on-screen needs to be declared.
-  (if (not (string-match "XEmacs\\|Lucid" emacs-version))
-      (progn
-       (make-local-variable 'show-paren-mode)
-       (setq show-paren-mode t))
-    (paren-set-mode 'paren))
-
-  (if (not (string-match "XEmacs\\|Lucid" emacs-version))
-      (progn
-       (make-local-variable 'show-paren-function)
-       ;;(setq show-paren-function 'LilyPond-show-paren-function) ; possible ?
-       )
-    (progn
-      (make-local-variable 'paren-highlight)
-      ;;(setq paren-highlight 'LilyPond-paren-highlight) ; possible ?
-      ))
-
   ;; In XEmacs imenu was synched up with: FSF 20.4
   (make-local-variable 'imenu-generic-expression)
   (setq imenu-generic-expression LilyPond-imenu-generic-expression)
-  (imenu-add-to-menubar "Index")
+  ;; (imenu-add-to-menubar "Index") ; see LilyPond-add-imenu-menu
 
   ;; In XEmacs one needs to use 'easy-menu-add'.
   (if (string-match "XEmacs\\|Lucid" emacs-version)
@@ -1136,6 +1127,23 @@ LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
       (setq zmacs-regions nil)
     (setq mark-even-if-inactive t))
 
+  ;; Context dependent syntax tables in Lilypond-mode
+  (make-local-hook 'post-command-hook) ; XEmacs requires
+  (add-hook 'post-command-hook 'LilyPond-mode-context-set-syntax-table nil t)
+
+  ;; Turn on paren-mode buffer-locally, i.e., in LilyPond-mode
+  (if (string-match "XEmacs\\|Lucid" emacs-version)
+      (progn
+       (make-local-variable 'paren-mode)
+       (paren-set-mode 'paren)
+       (make-local-variable 'blink-matching-paren)
+       (setq blink-matching-paren t)
+       )
+    (progn
+      (make-local-variable 'blink-matching-paren-on-screen)
+      (setq blink-matching-paren-on-screen t)
+     ))
+
   ;; run the mode hook. LilyPond-mode-hook use is deprecated
   (run-hooks 'LilyPond-mode-hook))