summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--ebuild-mode.el28
-rw-r--r--test/ebuild-mode-tests.el25
3 files changed, 60 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index fca3953..81da37f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2024-09-28 Ulrich Müller <ulm@gentoo.org>
+ * ebuild-mode.el (ebuild-mode-enable-bug-reference):
+ New custom variable.
+ (ebuild-mode-bug-regexp, ebuild-mode-bug-url-format):
+ New variables.
+ (ebuild-repo-mode): Conditionally enable bug-reference-prog-mode.
+ * test/ebuild-mode-tests.el (ebuild-mode-test-bug-url): New test.
+
* ebuild-mode.el (ebuild-repo-mode): Define the nxml-* variables
instead of requiring nxml-mode at compile time.
diff --git a/ebuild-mode.el b/ebuild-mode.el
index e0edb6c..d826b32 100644
--- a/ebuild-mode.el
+++ b/ebuild-mode.el
@@ -101,6 +101,11 @@ If nil, don't update."
:type 'boolean
:group 'ebuild)
+(defcustom ebuild-mode-enable-bug-reference t
+ "If non-nil, enable `bug-reference-prog-mode' in `ebuild-repo-mode'."
+ :type 'boolean
+ :group 'ebuild)
+
(defcustom ebuild-mode-xml-indent-tabs nil
"If non-nil, use tab characters for indenting of XML.
If nil, use two spaces."
@@ -962,6 +967,19 @@ This will be added to the `write-contents-functions' hook."
This excludes `comment-start'. See `ebuild-mode-insert-tag-line'
for the format of the tag line.")
+(defvar ebuild-mode-bug-regexp
+ "\\(\\(?:\\b[Bb]ug *[ #]\\|#\\)\\([0-9]\\{4,\\}\\)\\)"
+ "Regular expression matching bug references.
+The format is the same as for `bug-reference-bug-regexp', which see.")
+
+(defvar ebuild-mode-bug-url-format
+ "https://bugs.gentoo.org/%s"
+ "Format used to turn a bug number into a URL.
+The bug number is supplied as a string, so this should have a single %s.
+See `bug-reference-url-format' for further details.")
+
+(defvar bug-reference-bug-regexp) ; bug-reference.el
+(defvar bug-reference-url-format)
(defvar nxml-child-indent) ; nxml-mode.el
(defvar nxml-attribute-indent)
@@ -986,6 +1004,16 @@ for the format of the tag line.")
(setq fill-column 72))
(unless (local-variable-p 'tab-width (current-buffer))
(setq tab-width 4))
+ (static-if (fboundp 'bug-reference-prog-mode)
+ (progn
+ (unless (local-variable-p 'bug-reference-bug-regexp (current-buffer))
+ (set (make-local-variable 'bug-reference-bug-regexp)
+ ebuild-mode-bug-regexp))
+ (unless (local-variable-p 'bug-reference-url-format (current-buffer))
+ (set (make-local-variable 'bug-reference-url-format)
+ ebuild-mode-bug-url-format))
+ (if ebuild-mode-enable-bug-reference
+ (bug-reference-prog-mode 1))))
(cond
((derived-mode-p 'conf-unix-mode)
(unless (local-variable-p 'paragraph-separate (current-buffer))
diff --git a/test/ebuild-mode-tests.el b/test/ebuild-mode-tests.el
index e714796..7ed6b85 100644
--- a/test/ebuild-mode-tests.el
+++ b/test/ebuild-mode-tests.el
@@ -249,6 +249,31 @@
"DEPEND=\"${RDEPEND}\"\n"
"BDEPEND=\"\"\n"))))))
+(ert-deftest ebuild-mode-test-bug-url ()
+ (skip-unless (fboundp 'bug-reference-prog-mode))
+ (let* ((ebuild-mode-enable-bug-reference t)
+ url-found
+ (browse-url-browser-function
+ (lambda (url &rest _args) (setq url-found url))))
+ (with-temp-buffer
+ (insert "# abc #876543 xyz\n"
+ "# bug 765432\n")
+ (ebuild-mode-test-run-silently
+ (ebuild-mode))
+ (bug-reference-fontify (point-min) (point-max))
+ (goto-char (point-min))
+ (search-forward "#" nil nil 2)
+ (bug-reference-push-button (point))
+ (should (equal url-found "https://bugs.gentoo.org/876543"))
+ (setq url-found nil)
+ (search-forward "bug")
+ (bug-reference-push-button (point))
+ (should (equal url-found "https://bugs.gentoo.org/765432"))
+ (setq url-found nil)
+ (bug-reference-push-button (point-min))
+ (bug-reference-push-button (point-max))
+ (should-not url-found))))
+
(ert-deftest ebuild-mode-test-insert-tag-line ()
(let ((ebuild-mode-full-name "Larry the Cow")
(ebuild-mode-mail-address "larry@example.org"))