Skip to content

Instantly share code, notes, and snippets.

@Compro-Prasad
Created June 22, 2019 05:15
Show Gist options
  • Save Compro-Prasad/58eeec31f8cfd130e704d3f0b5a5069b to your computer and use it in GitHub Desktop.
Save Compro-Prasad/58eeec31f8cfd130e704d3f0b5a5069b to your computer and use it in GitHub Desktop.
How to make clickable text in Emacs?
(defun compro/print-message (event)
"This function runs when you click the text."
(interactive "e")
(message "Hello World"))
(let* ((str "Click Me") ;; The text that will be produced
(str-beg 0) ;; Start position of string
(str-end (string-width str)) ;; End position of string
(map (make-sparse-keymap))) ;; Click event will be registered here
(define-key map [mouse-1] 'compro/print-message) ;; Register click event
(add-text-properties ;; Function that makes the text clickable
str-beg
str-end
`(
mouse-face highlight ;; Highlight the text on mouse hover
help-echo "mouse-1: visit this file in other window" ;; Tootip on mouse hover
keymap ,map) ;; Assign click to the str
str) ;; The string str which will get modified
(insert str)) ;; Insert the the text in the buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment