all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Jeff Filipovits <jrfilipovits@gmail.com>,
	Adam Spiers <orgmode@adamspiers.org>
Cc: Protesilaos Stavrou <info@protesilaos.com>,
	emacs-orgmode@gnu.org, Eric S Fraga <e.fraga@ucl.ac.uk>
Subject: Re: variable-pitch-mode misaligns org-mode heading tags
Date: Fri, 18 Sep 2020 20:49:50 +0800	[thread overview]
Message-ID: <87lfh745ch.fsf@localhost> (raw)
In-Reply-To: <877dst5fdf.fsf@gmail.com>

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.


  parent reply	other threads:[~2020-09-18 12:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 19:31 variable-pitch-mode misaligns org-mode heading tags Protesilaos Stavrou
2020-09-09  8:44 ` Bastien
2020-09-09 11:03   ` Eric S Fraga
2020-09-09 14:39     ` Bastien
2020-09-15 17:41       ` Jeff Filipovits
2020-09-16 16:21         ` Adam Spiers
2020-09-16 19:03           ` Jeff Filipovits
2020-09-16 21:14             ` Samuel Wales
2020-09-16 22:55             ` Adam Spiers
2020-09-17  0:18               ` Adam Spiers
2020-09-17  2:03               ` Jeff Filipovits
2020-09-17 15:36                 ` Jeff Filipovits
2020-09-18 12:49                 ` Ihor Radchenko [this message]
2021-04-27 19:41           ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lfh745ch.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=e.fraga@ucl.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --cc=info@protesilaos.com \
    --cc=jrfilipovits@gmail.com \
    --cc=orgmode@adamspiers.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.