[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: variable-pitch-mode misaligns org-mode heading tags
From: |
Ihor Radchenko |
Subject: |
Re: variable-pitch-mode misaligns org-mode heading tags |
Date: |
Fri, 18 Sep 2020 20:49:50 +0800 |
I somehow missed this thread.
I have a (mostly) working code achieving the same thing in my personal
config. The code is below. Hope it can give you some more ideas.
I am using font-lock for tag alignment.
(add-hook 'org-mode-hook (lambda () (font-lock-add-keywords 'org-mode
'(yant/org-align-tags) t)) 100)
(add-hook 'org-mode-hook (lambda () (add-to-list 'font-lock-extra-managed-props
'org-tag-aligned)))
(defun yant/org-align-tags (limit &optional force)
"Align all the tags in org buffer."
(save-match-data
(when (eq major-mode 'org-mode)
(while (re-search-forward "^\\*+ \\(.+?\\)\\([ \t]+\\)\\(:\\(?:[^
\n]+:\\)+\\)$" limit t)
(when (and (match-string 2)
(or force
(not (get-text-property (match-beginning 2)
'org-tag-aligned))))
(with-silent-modifications
(put-text-property (match-beginning 2) (match-end 2)
'org-tag-aligned t)
(put-text-property (if (>= 2 (- (match-end 2) (match-beginning
2)))
(match-beginning 2)
;; multiple whitespaces may mean that we are
in process of typing
(1+ (match-beginning 2)))
(match-end 2)
'display
`(space . (:align-to (- right
(,(+ 3 ;; no idea, but
otherwise it is sometimes not enough
(string-display-pixel-width org-ellipsis)
(string-display-pixel-width (or (match-string 3)
""))))))))))))))
(defun string-display-pixel-width (string &optional mode)
"Calculate pixel width of STRING.
Optional MODE specifies major mode used for display."
(with-temp-buffer
(with-silent-modifications
(setf (buffer-string) string))
(when (fboundp mode)
(funcall mode)
(font-lock-fontify-buffer))
(if (get-buffer-window (current-buffer))
(car (window-text-pixel-size nil (line-beginning-position) (point)))
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size nil (line-beginning-position) (point))))))
Jeff Filipovits <jrfilipovits@gmail.com> writes:
> Adam Spiers <orgmode@adamspiers.org> writes:
>
>> Hrm, no this isn't good enough. For graphical windows we still
>> need
>> to set the display text properties to align all tags when the
>> buffer
>> initially loads. AFAICS there's currently no code to trigger
>> this, so
>> it would need to be added, and for large files this might
>> actually
>> cause problems with file loading time unless it was done in the
>> background (a bit like fontification can be done).
>
>
>
> The upside of this is that it enabled me do to some hacking so now
> I can use a variable pitch font in the mu4e headers view and keep
> the columns aligned, which makes mu4e much prettier.
>
>
> --
> Jeff Filipovits
> Spears & Filipovits, LLC
> 1126 Ponce de Leon Avenue
> Atlanta, GA 30306
> 678.237.9302 (direct)
> jeff@civil-rights.law
>
> All emails confidential to the fullest extent of the law.
- Re: variable-pitch-mode misaligns org-mode heading tags, (continued)
- Re: variable-pitch-mode misaligns org-mode heading tags, Eric S Fraga, 2020/09/09
- Re: variable-pitch-mode misaligns org-mode heading tags, Bastien, 2020/09/09
- Re: variable-pitch-mode misaligns org-mode heading tags, Jeff Filipovits, 2020/09/15
- Re: variable-pitch-mode misaligns org-mode heading tags, Adam Spiers, 2020/09/16
- Re: variable-pitch-mode misaligns org-mode heading tags, Jeff Filipovits, 2020/09/16
- Re: variable-pitch-mode misaligns org-mode heading tags, Samuel Wales, 2020/09/16
- Re: variable-pitch-mode misaligns org-mode heading tags, Adam Spiers, 2020/09/16
- Re: variable-pitch-mode misaligns org-mode heading tags, Adam Spiers, 2020/09/16
- Re: variable-pitch-mode misaligns org-mode heading tags, Jeff Filipovits, 2020/09/16
- Re: variable-pitch-mode misaligns org-mode heading tags, Jeff Filipovits, 2020/09/17
- Re: variable-pitch-mode misaligns org-mode heading tags,
Ihor Radchenko <=