branch: elpa/rpm-spec-mode
commit 9e4fcfe7cd58008fbb8db2cfbef02474dbcc779a
Author: Peter Oliver <g...@mavit.org.uk>
Commit: Björn Bidar <bjorn.bi...@thaodan.de>

    Quote/unquote macros when commenting/uncommenting
    
    If we don’t do this, the user will get warnings about macro expansion in 
comments.
---
 rpm-spec-mode.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/rpm-spec-mode.el b/rpm-spec-mode.el
index 681e781d4c..bb8cf5ee5c 100644
--- a/rpm-spec-mode.el
+++ b/rpm-spec-mode.el
@@ -692,6 +692,21 @@ value returned by function `user-mail-address'."
   "Additional expressions to highlight in `rpm-spec-mode'.")
 
 
+(defun rpm-spec-mode-comment-region (beg end &optional arg)
+  "Comment between BEG and END, replacing % with %% to prevent macro expansion.
+ARG is passed on to `comment-region-default'."
+  (comment-region-default beg
+                          (+ end (replace-string-in-region "%" "%%" beg end))
+                          arg))
+
+(defun rpm-spec-mode-uncomment-region (beg end &optional arg)
+  "Uncomment between BEG and END, replacing %% with % to reenable macro 
expansion.
+ARG is passed on to `uncomment-region-default'."
+  (uncomment-region-default beg
+                            (- end (replace-string-in-region "%%" "%" beg end))
+                            arg))
+
+
 (defvar rpm-spec-mode-abbrev-table nil
   "Abbrev table in use in `rpm-spec-mode' buffers.")
 (define-abbrev-table 'rpm-spec-mode-abbrev-table ())
@@ -765,6 +780,8 @@ with no args, if that value is non-nil."
   (setq-local comment-column 32)
   (setq-local comment-start-skip "#+ *")
 ;  (setq-local comment-indent-function 'c-comment-indent)
+  (setq-local comment-region-function #'rpm-spec-mode-comment-region)
+  (setq-local uncomment-region-function #'rpm-spec-mode-uncomment-region)
   ;;Initialize font lock for GNU emacs.
   (make-local-variable 'font-lock-defaults)
   (font-lock-add-keywords nil rpm-spec-font-lock-keywords)

Reply via email to