From 50cf4ec92dcafa6d2f3d520fd8569b3852a99595 Mon Sep 17 00:00:00 2001
From: hjunes <hjunes>
Date: Thu, 10 Jul 2003 19:00:05 +0000
Subject: [PATCH] new function: LilyPond-show-paren-mode

---
 ChangeLog          |  9 +++++++++
 lilypond-indent.el | 49 ++++++++++++++++++++++++++++++++++++++++++++--
 lilypond-mode.el   | 47 ++++++++++++++++++++++----------------------
 3 files changed, 79 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9609ad4d02..1461e8f492 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-07-10  Heikki Junes  <hjunes@cc.hut.fi>
+
+	* lilypond-indent.el (LilyPond-show-paren-mode): From Emacs' paren.el:
+	Disable buffer-locally default paren idle timer and make a new one. 
+
+	* lilypond-mode.el: Turn off locally show-paren-mode, but turn on
+	locally LilyPond-show-paren-mode. Add to menu a toggle for
+	LilyPond-show-paren-function.
+
 2003-07-08  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
 	* input/template/jazz-combo.ly (drumNotes): 1.7 fixes 
diff --git a/lilypond-indent.el b/lilypond-indent.el
index 0ba6240fd4..e9e7b90c65 100644
--- a/lilypond-indent.el
+++ b/lilypond-indent.el
@@ -17,7 +17,7 @@
 ;;;    * in syntax-highlighting slurs are not always highlighted the right way
 ;;;      e.g. opening slurs are found found better in "#( ( ) ( ) )" than
 ;;;      opening slurs
-;;;    * should make Lilypond-show-paren-mode instead of using show-paren-mode
+;;;    * XEmacs: should make Lilypond-paren-mode instead of using paren-mode
 
 (defcustom LilyPond-indent-level 4
   "*Indentation of lilypond statements with respect to containing block.")
@@ -574,7 +574,7 @@ in XEmacs' paren-highlight."
 ;; Find the place to show, if there is one,
 ;; and show it until input arrives.
 (defun LilyPond-show-paren-function ()
-  (if show-paren-mode
+  (if LilyPond-show-paren-mode
       (let (pos dir mismatch face (oldpos (point)))
 	(cond ((eq (char-syntax (preceding-char)) ?\))
 	       (setq dir -1))
@@ -769,3 +769,48 @@ and the following faces:
 					    nil
 					    paren-blink-interval))))))
 	))))
+
+(if (not (string-match "XEmacs\\|Lucid" emacs-version))
+;;; EMACS' Lilypond-show-paren-mode definition
+(define-minor-mode LilyPond-show-paren-mode
+  "Toggle Show Paren mode.
+With prefix ARG, turn Show Paren mode on if and only if ARG is positive.
+Returns the new status of Show Paren mode (non-nil means on).
+
+When Show Paren mode is enabled, any matching parenthesis is highlighted
+in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
+  :global t :group 'LilyPond-paren-showing
+    ;; Turn off the usual paren-matching method
+    ;; when this one is turned on.
+    (if (local-variable-p 'LilyPond-show-paren-mode)
+	(make-local-variable 'blink-matching-paren-on-screen)
+      (kill-local-variable 'blink-matching-paren-on-screen))
+    (setq blink-matching-paren-on-screen (not LilyPond-show-paren-mode))
+    ;; Now enable or disable the mechanism.
+    ;; First get rid of the old idle timer.
+    (if show-paren-idle-timer
+	(cancel-timer show-paren-idle-timer))
+    (if (boundp 'LilyPond-show-paren-idle-timer)
+	(cancel-timer LilyPond-show-paren-idle-timer))
+    (setq LilyPond-show-paren-idle-timer nil)
+    ;; If show-paren-mode is enabled in some buffer now,
+    ;; set up a new timer.
+    (when (memq t (mapcar (lambda (buffer)
+			    (or (with-current-buffer buffer
+				  show-paren-mode)
+				(with-current-buffer buffer
+				  LilyPond-show-paren-mode)))
+			  (buffer-list)))
+      (setq LilyPond-show-paren-idle-timer (run-with-idle-timer
+					    show-paren-delay t
+					    'LilyPond-show-paren-function)))
+    (unless show-paren-mode
+      (and show-paren-overlay
+	   (eq (overlay-buffer show-paren-overlay) (current-buffer))
+	   (delete-overlay show-paren-overlay))
+      (and show-paren-overlay-1
+	   (eq (overlay-buffer show-paren-overlay-1) (current-buffer))
+	   (delete-overlay show-paren-overlay-1))))
+;;; XEMACS' Lilypond-paren-mode definition
+(progn ; TODO
+))
diff --git a/lilypond-mode.el b/lilypond-mode.el
index 44ea6075bb..ec69823541 100644
--- a/lilypond-mode.el
+++ b/lilypond-mode.el
@@ -22,7 +22,7 @@
 (require 'easymenu)
 (require 'compile)
 
-(defconst LilyPond-version "1.7.21"
+(defconst LilyPond-version "1.7.24"
   "`LilyPond-mode' version number.")
 
 (defconst LilyPond-help-address "bug-lilypond@gnu.org"
@@ -999,6 +999,13 @@ command."
 	     ["(Un)comment Region" LilyPond-comment-region t]
 	     ["Refontify buffer" font-lock-fontify-buffer t]
 	     ["Add index menu" LilyPond-add-imenu-menu]
+	     ["LilyPond Paren Mode" 
+	      (if (not (string-match "XEmacs\\|Lucid" emacs-version))
+		  (LilyPond-show-paren-mode (not LilyPond-show-paren-mode))
+		(paren-set-mode (and (not paren-mode) 'paren)))
+	      :style toggle :selected 
+	      (if (not (string-match "XEmacs\\|Lucid" emacs-version))
+		  LilyPond-show-paren-mode paren-mode)]
  	     ))
 	  '(("Info"
 	     ["LilyPond" LilyPond-info t]
@@ -1111,29 +1118,6 @@ LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
   (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) ; possible?
-	;; (setq show-paren-function 'LilyPond-show-paren-function) ; possible?
-	;;  don't redefine emacs functions. It breaks other modes.
-	;;  should have an own idle-timer instead
-	;; (defun show-paren-function () (LilyPond-show-paren-function)) ; for testing
-	)
-    (progn
-      ;; (make-local-variable 'paren-highlight) ; possible?
-      ;; (setq paren-highlight 'LilyPond-paren-highlight) ; possible?
-      ;;  don't redefine Xemacs functions. It breaks other modes.
-      ;;  should have an own idle-timer instead
-      ;; (defun paren-highlight () (LilyPond-paren-highlight)) ; for testing
-      ))
-
   ;; In XEmacs imenu was synched up with: FSF 20.4
   (make-local-variable 'imenu-generic-expression)
   (setq imenu-generic-expression LilyPond-imenu-generic-expression)
@@ -1150,6 +1134,21 @@ LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
       (setq zmacs-regions nil)
     (setq mark-even-if-inactive t))
 
+  ;; In Emacs blink-...-on-screen needs to be declared.
+  (if (not (string-match "XEmacs\\|Lucid" emacs-version))
+      (progn
+	(make-local-variable 'show-paren-mode)
+	(show-paren-mode nil)
+	(make-local-variable 'LilyPond-show-paren-mode)
+	(LilyPond-show-paren-mode t))
+    (progn 
+      (make-local-variable 'show-paren-mode)
+      (paren-set-mode 'paren)
+      ;;  don't redefine Xemacs functions. It breaks other modes.
+      ;;  should have an own idle-timer instead
+      ;; (defun paren-highlight () (LilyPond-paren-highlight)) ; for testing
+      ))
+
   ;; run the mode hook. LilyPond-mode-hook use is deprecated
   (run-hooks 'LilyPond-mode-hook))
 
-- 
2.39.5