emacs/elisp: What is the hash (pound, number sign, octothorp) symbol used for?

前端 未结 3 1704
情书的邮戳
情书的邮戳 2020-12-07 14:10

What does this do?

(add-hook \'compilation-mode-hook #\'my-setup-compile-mode)

...and is it different than

(add-hook \'com         


        
3条回答
  •  日久生厌
    2020-12-07 15:08

    I found this question while searching for what the hash meant in something I found while hacking mode-line-format:

    #("-%-" 0 3
      (help-echo "Display as tooltip when mouse hovers or with display-local-help."))
    

    which is a format used for text properties in strings where:

    • "-%-", text to be propertized: one dash and a %-construct that results in "dashes sufficient to fill the remainder of the mode line", resulting in the famous Emacs ------.
    • 0, the first character upon which the text properties apply.
    • 3, the last character upon which the text properties apply, i.e. the entire "-%-".
    • (help-echo "..."), a property and a string as its argument.

    This can be created with the propertize function:

    (propertize "Hover over me!" 'help-echo '"congratulations!")
    

    (insert (propertize

    would be the same as #("Hover over me!" 0 14 (help-echo "Congratulations!")):

    Small example.

    If you're using font lock mode, using the buffer-substring command might produce something like this:

    (buffer-substring 1 28) ; First 27 characters in the current buffer
     ⇒ #(";; This buffer is for notes"
         0 3
         (fontified t face font-lock-comment-delimiter-face)
         3 27
         (fontified t face font-lock-comment-face))
    

    So you could create something like:

    Showing the corresponding propertize function for multiple properties.

提交回复
热议问题