Skip to main content
2 of 2
edited tags
Drew
  • 79.1k
  • 10
  • 123
  • 257

Interactive option for function with optional arguments

Am unsure whether making brcmk-end optional is possible for interactive use. If one can have optional arguments, what would be the changed necessary? Would the interactive expression change?


    (defun rk-bracemk-count-2 (brcmk-beg brcmk-end rgn-beg rgn-end)
      "Count brace marks within a selected region.
    
    BRCMK-BEG  Opening brace mark.
    BRCMK-END  Closing brace mark.
    RGN-BEG    Region start marker or position.
    RGN-END    Region end marker or position."
    
      (interactive
       (list (read-char-from-minibuffer "Opening bracemark: ")
             (read-char-from-minibuffer "Closing bracemark: ")
             (region-beginning)
             (region-end) ))
      
      (save-excursion
        (let ( ($a  0) ($b  0) 
               ($begmk  (char-to-string brcmk-beg))
               ($endmk  (char-to-string brcmk-end)) )
    
          (goto-char rgn-beg)
          (while (and (< (point) rgn-end)
                      (search-forward $begmk rgn-end t))
            (cl-incf $a))
    
          (goto-char rgn-beg)
          (while (and (< (point) rgn-end)
                      (search-forward $endmk rgn-end t))
            (cl-incf $b))
    
          (message "Marks: %s %s  Counts: %d %d" $begmk $endmk $a $b)
          (goto-char rgn-beg) )))

Dilna
  • 1
  • 3
  • 13