代码之家  ›  专栏  ›  技术社区  ›  Mahavir

pcase无法识别字符串匹配

  •  0
  • Mahavir  · 技术社区  · 1 年前

    我试图插入Latex命令或UTF-8符号 到缓冲区,但是 pcase 正在给我 "No Match" 选择时 "bigodot"

    grafm 中预期我通过删除修改 UTF-8 符号,依据 将第一个单词放在第一个空格之前,只使用字符串 描述符 “bigodot” 用于 pcase 条款

    
    (defun imprint (selector kmstr &optional grapheme)
      "Insert Latex Command or the equivalent UTF-8 grapheme."
    
      (if (or (not grapheme) (equal selector "Command"))
          (insert kmstr)
        (insert grapheme)))
    
    ;;-------------------------------------
    
    (defun bigops (grafm seltr)
      "Binary Operations."
    
      (interactive
        (let ( (csel '("Symbol" "Command"))
               (cseq '("bigodot ⨀" "bigoplus ⨁︁" "bigotimes ⨂︁")) )
    
          (list
            (completing-read "Grapheme: " cseq nil t "bigcap ⋂")
            (completing-read "Selector: " csel nil t "Command")) ))
    
      (setq grafm (car (split-string grafm)))
      (message "Grafm: .%S." grafm)
    
      (pcase grafm
        ("bigodot" (imprint seltr "\\bigodot" "⨀"))
        ("bigoplus︁" (imprint seltr "\\bigoplus" "⨁︁"))
        ("bigotimes︁" (imprint seltr "\\bigotimes" "⨂︁"))
        (_  (message "%s" "No Match")) ))
    
    0 回复  |  直到 1 年前
        1
  •  0
  •   Rorschach    1 年前

    在您输入的字符串中的各个位置都有隐藏的字符,代码点65025 pcase 导致意外匹配失败的匹配。

    您可以使用将它们可视化

    (defun my-display-hidden (&optional remove)
      "Show/hide the hidden '︁' (0xfe01) characters."
      (interactive "P")
      (if remove (remove-overlays)
        (save-excursion
          (goto-char (point-min))
          (while (search-forward "︁" nil t) ; (0xfe01)
            (let ((ov (make-overlay (match-beginning 0) (match-end 0))))
              (overlay-put ov 'display
                           (buttonize "(0xfe01)"
                                      (let ((pos (match-beginning 0)))
                                        (lambda (_) (describe-char pos)))))
              (overlay-put ov 'face 'font-lock-warning-face))))))