From a2267744cfdddaab6a4a60b8bfa31ba86724d614 Mon Sep 17 00:00:00 2001 From: Heikki Junes Date: Mon, 16 Jun 2003 21:58:25 +0000 Subject: [PATCH] (un)comment lines in region independently. --- ChangeLog | 10 +++++++++- lilypond-indent.el | 24 +++++++++++++++++++++++- lilypond-mode.el | 12 ++---------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d01475926..a4a9fdcc62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-06-17 Heikki Junes + + * lilypond-mode.el (LilyPond-un-comment-region): removed. + Use one command for both commenting and uncommenting. + + * lilypond-indent.el (LilyPond-comment-region): new function, + (un)comments each line separately. + 2003-06-16 Heikki Junes * lilypond-mode.el: Set show-paren-mode local; minor-mode @@ -9,7 +17,7 @@ XEmacs' paren-highlight and make minimal changes; add comments about locality. Fix matching first open-paren-char in '<< .. >>'. - + 2003-06-16 Graham Percival * input/test/g*: added texidoc index. diff --git a/lilypond-indent.el b/lilypond-indent.el index cdf7cb9771..814ffce0bb 100644 --- a/lilypond-indent.el +++ b/lilypond-indent.el @@ -3,6 +3,7 @@ ;;; Heikki Junes ;;; * redefine Emacs' show-paren-function and XEmacs' paren-highlight ;;; * match two-char slurs '\( ... \)' and '\[ ... \]' separately. +;;; * adopt Emacs' f90-comment-region ;;; Chris Jackson ;;; some code is taken from ESS (Emacs Speaks Statistics) S-mode by A.J.Rossini @@ -51,6 +52,28 @@ Compares with other text in same context.") (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. @@ -129,7 +152,6 @@ Returns nil if line starts inside a string" (current-indentation))))))))) - (defun LilyPond-indent-line () "Indent current line as lilypond code. Return the amount the indentation changed by." diff --git a/lilypond-mode.el b/lilypond-mode.el index 26df4e5ad7..9fbe6dad1a 100644 --- a/lilypond-mode.el +++ b/lilypond-mode.el @@ -513,12 +513,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 +680,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,8 +992,7 @@ 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] )) '(("Info" -- 2.39.5