1

I know there is a function called: facemenu-set-bold, which is bound to M-o b, but I'm trying to write my own as an exercise. Here is my code:

(defun my-function()
  "this is my function"
  (interactive)
  (facemenu-set-face 'bold))

When I select a region and call this function using M-x my-function, the region itself is not affected, only the newly inserted text is bold, can someone please, explain to me why.

  • Do you want to do it with text-properties; or, would you prefer to do it with overlays? – lawlist Oct 28 '18 at 19:52
  • The easiest one, I'm not sure of what 'overlays' mean. – Bite Bytes Oct 28 '18 at 20:36
  • 1
    See function put-text-property (for property face) - C-h f. – Drew Oct 29 '18 at 2:13
1

facemenu-set-face checks the active region within its interactive form. If you call it as a function that form is not evaluated.

If you would call it through call-interactively then the interactive form of facemenu-set-face also asks for the face. That is also something you probably do not want.

If you insist on using facemenu-set-face the way out is to provide the arguments START and END yourself. You can copy the relevant lines from the interactive-form of facemenu-set-face. If you have installed the elisp sources you find the definition of facemenu-set-face by:
M-x find-function RET facemenu-set-face RET.

(defun my-function()
  "this is my function"
  (interactive)
  (facemenu-set-face 'bold
             (if (and mark-active (not current-prefix-arg))
             (region-beginning))
             (if (and mark-active (not current-prefix-arg))
             (region-end))
             ))
  • When I type M-x find-function RET facemenu-set-function RET I get [no match], and when I use M-. I get No definitions found for: facemenu-set-function, how can I fix this please? – Bite Bytes Oct 29 '18 at 15:26
  • 1
    @BiteBytes That was a typo. I've corrected the answer. – Tobias Oct 29 '18 at 15:28

Your Answer

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

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