1

If i have a writable buffer, i can use this to insert hyperlink.

(require 'button)
(insert-button "foo" 'action (lambda (x) (find-file "~/test.py")))

But i have to add clickable text property to a piece of text in read only buffer. I am trying this

(add-text-properties
 1
 50
 '(lambda (x) (find-file "~/test.py")))

But it is throwing this error

Debugger entered--Lisp error: (error "Odd length text property list")

Any suggestion to solve this?

1 Answer 1

4

The reason for the error is that you did not use the correct format to add a text property.

quote from manual:

Function: add-text-properties start end props &optional object

The argument props specifies which properties to add. It should have the form of a property list (see Property Lists): a list whose elements include the property names followed alternately by the corresponding values.

However, for your specific problem, emacs has a different command: emacs lisp manual excerpt

The following functions add a button using an overlay (see Overlays) to hold the button properties: Function: make-button beg end &rest properties

This makes a button from beg to end in the current buffer, and returns it.

If you insist on doing it via text properties, see above link for

Function: make-text-button beg end &rest properties

Example code for specific problem:

(make-button 1 50 'action (lambda(x) (find-file "~/test.py")))
2
  • Welcome. This answer would be even better giving the correct code in this particular context. Sep 10, 2015 at 12:03
  • code example added
    – timor
    Sep 10, 2015 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.