Search code examples
emacselisppython-mode

Why doesn't button-lock-mode work with python-mode in Emacs?


I'd like to have clickable links to JIRA tickets in my Python code from within Emacs.

For example, I use doxygen docstrings in my integration test code, which links a ticket number:

def test_user_type_isolation(self):
    """
    Ensure UDT cannot be used from another keyspace
    @jira_ticket CASSANDRA-9409
    @since 2.2
    """
    ....

I'd like to be able to click the CASSANDRA-9409 and have it go directly to the JIRA ticket it's referencing. I found button-lock-mode and it works great! However, this elisp works in every mode except for python-mode:

(require 'button-lock)
(global-button-lock-mode 1)

(setq cassandra-jira-button
      (button-lock-set-button "CASSANDRA-[0-9]+"
        #'(lambda ()
            (interactive)
            (browse-url (concat "https://issues.apache.org/jira/browse/"
                         (thing-at-point 'symbol)))
        )
    :face 'link :face-policy 'prepend))

It's not just my code though, none of the examples included in button-lock.el work in python-mode either. So, does anyone know what might be causing the conflict?


Solution

  • I don't know anything about button-lock-mode, but Emacs comes with bug-reference-mode, and the very useful sub-mode bug-reference-prog-mode. I would suggest using those instead. For your use you would want to configure this via bug-reference-bug-regexp and bug-reference-url-format.

    bug-reference-prog-mode is handy because it limits its buttonizing behavior to comments and strings -- perfect for programming modes.