Created
June 22, 2019 05:15
-
-
Save Compro-Prasad/58eeec31f8cfd130e704d3f0b5a5069b to your computer and use it in GitHub Desktop.
How to make clickable text in Emacs?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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