Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to tidy attributes #28

Open
zrquan opened this issue Feb 8, 2025 · 0 comments · May be fixed by #29
Open

Allow to tidy attributes #28

zrquan opened this issue Feb 8, 2025 · 0 comments · May be fixed by #29

Comments

@zrquan
Copy link

zrquan commented Feb 8, 2025

能否提供一个设置项,支持隐藏 #+attr_xxx: ... 这种属性行

我尝试做了些实现想提 pr,但是我 elisp 太菜了,遇到一些奇怪的 bug 无法解决——比如光标会被隐藏的属性行“挡住”不能向下移动。。。

一些修改:

(defun org-tidy--element-attr-p (e)
  (or
   (org-element-property :attr_org e)
   (org-element-property :attr_html e)))

(defun org-tidy--get-element-pos (element is-attr type)
  "Get position of TYPE from ELEMENT based on org version."
  (if (version< org-version "9.7")
      ;; 老版本使用 property
      (org-element-property type element)
    ;; 新版本使用函数
    (pcase type
      (:begin (org-element-begin element))
      (:end (if is-attr
                (org-element-contents-begin element)
              (org-element-end element)))
      (_ (org-element-property type element)))))

(defun org-tidy--element-to-ov (element)
  "Turn a single property ELEMENT into a plist for merge."
  (let* ((is-attr (org-tidy--element-attr-p element))
         (should-tidy (or (org-tidy-should-tidy element) is-attr))
         (beg (org-tidy--get-element-pos element is-attr :begin))
         (end (org-tidy--get-element-pos element is-attr :end))
         (is-top-property (= 1 beg))
         (push-ovly nil)
         (display nil))

    (pcase (list is-top-property org-tidy-top-property-style
                 org-tidy-properties-style)
      (`(t invisible ,_)
       (setq display 'empty push-ovly t))

      (`(t keep ,_) )

      (`(nil ,_ invisible)
       (setq display 'empty push-ovly t))

      (`(nil ,_ inline)
       (setq display 'inline-symbol push-ovly t))

      (`(nil ,_ fringe)
       (setq display 'fringe push-ovly t)))

    (when (and should-tidy push-ovly)
      (list :beg beg
            :end end
            :is-top-property is-top-property
            :display display))))

(defun org-tidy-buffer ()
  "Tidy."
  (interactive)
  (save-excursion
    (condition-case err
        (let* ((ast (org-element-parse-buffer))
               (raw-ovs (org-element-map ast
                           '(property-drawer drawer paragraph)
                         ......
@zrquan zrquan linked a pull request Feb 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant