I'm creating a 'form' of sorts in a buffer that has a few required arguments:


content content content

When the form is presented, I'd like to be able to edit any and all text after each Header: without being able to move point into Header: -- kindof like a minibuffer prompt.

After looking at the definition of read-from-minibuffer for the right properties, here's what I've got so far:

(defun my--insert-header (header &optional default-value)
  ;; inhibit point from moving inside the field
  (setq-local inhibit-point-motion-hooks nil)
  ;; insert Header: Default-Value pairs
  (let ((props1 '(front-sticky t rear-non-sticky t field t read-only t intangible t face magit-header-line))
        (props2 '(front-sticky nil rear-non-sticky nil field nil read-only nil intangible nil)))
    (insert (apply #'propertize (format "%s: " header) props1))
    (insert (apply #'propertize (or value "") props2))
    (insert (apply #'propertize "\n" props1))))

When I run this code in a scratch buffer

  (insert "\n\n\n")
  (my--insert-header "Title" "some title"))

I get an error. I think it's because (insert (apply #'propertize (or value "") props2)) is trying to insert at read-only text, but I'm not sure how to go about fixing that without compromising the desired behavior.

  • 3
    You have rear-non-sticky in your code, but it should be rear-nonsticky.
    – xuchunyang
    Feb 17 '17 at 14:09
  • Show the error you get. You can bind inhibit-read-only around your inserts.
    – Drew
    Feb 17 '17 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.