我的问题来自我期望一个可以将 org-mode 表转换为 ditaa 图的函数。我尝试做的是:
- 找到“|” 如果左/右/上/下有任何“-”,将其更改为“+”
- 如果没有“|”,则查找“+” 在左/右/上/下,将其更改为“-”
谁能告诉我如何搜索上方/下方的字符或整个功能?
首先,感谢@legoscia 的原始解决方案。
当我尝试(下一行)/(上一行)时,我遇到了一些问题,例如“缓冲区结束,缓冲区开始”。然后我在elisp手册中搜索。它建议使用前锋线。然后我在这里得到了解决方案:
(defun get-char-below (&optional point)
"Return the character one line down from POINT.
If POINT is nil or omitted, use the current position of point."
(save-excursion
(when point
(goto-char point))
(let ((column (current-column)))
(if (= (forward-line 1) 0)
(if (= column (move-to-column column))
(char-after)
nil)
nil))))
您可以使用这样的函数来检查下一行的内容:
(defun get-char-on-next-line (&optional point)
"Return the character one line down from POINT.
If POINT is nil or omitted, use the current position of point."
(save-excursion
(when point
(goto-char point))
(let ((column (current-column))
(line-move-visual nil))
;; next-line preserves the current column if possible
(next-line)
(when (= column (current-column))
(char-after)))))
替换next为previous相反的功能。