0

I am using funcall to set a typeface by calling a function select-typeface. I would like to remove select-typeface, calling (face (funcall level-typeface depth match).

Cannot simply do

 (let ( (face (funcall level-typeface depth match)) )

in function colourise.

I might remove funcall and just use

 (let ( (face (level-typeface depth match)) )

Changing from select-typeface to level-typeface has became problematic, because the face is not being applied at loc.

(defun level-typeface (depth match)
  "Typeface for colouring a nested glyph at a particular depth.

DEPTH  Depth level of nested glyph.
MATCH  Indicates whether glyph is matched by a closing brace.
LOC    Location of glyph.

Returns one of `pigment-N' (N=1..dmax), or 
`pigment-unmatched-typeface', or `pigment-mismatched-typeface'"

  (cond
   ( (<= depth 0) 'pigment-unmatched-typeface)
   ( (not match)  'pigment-mismatched-typeface)
   ( t
      (let* ( (dcur depth)
              (dmax maxdepth)
              (n (mod dcur dmax))
              (levn (number-to-string n)) )

    (when (= n 0) (setq levn "8"))
        (intern-soft (concat "pigment-" levn)) ))) )

(defcustom select-typeface #'level-typeface
   "Select typeface function for colouring."
   :tag "Select function for colourising glyphs."
   :type 'function
   :group 'rich)

(defun colourise (loc depth match)
  "Highlight a single glyph at LOC according to DEPTH.

LOC    Location of character to add text properties to.
DEPTH  Nested depth at LOC, which determines the face to use.
MATCH  For a mismatched glyph, MATCH is `nil'."

  (let ( (face (funcall select-typeface depth match)) )

    (when face
      (font-lock-prepend-text-property loc (1+ loc) 'face face) )))
Drew
  • 75,699
  • 9
  • 109
  • 225
Dilna
  • 1,173
  • 3
  • 10
  • Say what you mean by *"Changing to level-typeface the typeface is not being set properly."* Do you mean that you replaced `select-typeface` by `'level-typeface`? (If not, did you try that?) Show what you tried and say what behavior or what error you got. – Drew Jul 19 '22 at 01:19

1 Answers1

0

I think you're saying that you tried to *"remove select-typeface, using (funcall level-typeface depth match) instead of (funcall select-typeface depth match).

If so, it looks like you just forgot to quote the function name:

(funcall 'level-typeface depth match)

funcall is a function. It evaluates its arguments. If you use unquoted level-typeface that's taken as a variable name. What you presumably want is to pass the symbol level-typeface to funcall, not the value of that symbol as a variable.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Correct. Beginning to think of removing the `funcall` and call the function directly `(level-typeface depth match)`. – Dilna Jul 19 '22 at 01:36
  • 1
    Yes, if you're just coding a symbol statically as the function argument then there's no need to use `funcall`. – Drew Jul 19 '22 at 01:40