Git Product home page Git Product logo

Comments (7)

andersjohansson avatar andersjohansson commented on August 20, 2024

For what it’s worth, here is my code for pixel-aligning tags. Recently adapted to org-modern. Based on code by Ihor Radchenko at: https://orgmode.org/list/87lfh745ch.fsf@localhost/
Feel free to reuse:

(setq org-tags-column 0
      org-auto-align-tags nil)

;; avoid unneccesary calculations, I never need it.
(defalias 'org-align-tags #'ignore)

;; Inspired by Ihor Radchenko’s code at: https://orgmode.org/list/87lfh745ch.fsf@localhost/

(add-hook 'org-modern-mode-hook #'aj/org-set-tag-align-keywords)
(defun aj/org-set-tag-align-keywords ()
  (add-to-list 'font-lock-extra-managed-props 'org-tag-aligned)
  (font-lock-add-keywords nil '((yant/org-align-tags t)) 'append))

(defun aj/string-pixel-width (string &optional mode)
  "Calculate pixel width of STRING.
Optional MODE specifies major mode used for display."
  (let ((fra face-remapping-alist))
    (with-temp-buffer
      (with-silent-modifications
        (setf (buffer-string) string))
      (when (fboundp mode)
        (funcall mode)
        (font-lock-ensure))
      (setq-local face-remapping-alist fra)
      (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)))))))


(defun yant/org-align-tags (limit &optional force)
  "Align all the tags in org buffer."
  (save-match-data
    (when (eq major-mode 'org-mode)
      (let ((ellw (aj/string-pixel-width org-ellipsis)))
	    (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
							      ellw
                                  (if (match-beginning 3)
                                      (car (window-text-pixel-size nil (match-beginning 3) (match-end 3)))
                                    0))))))))))))))

aj/string-pixel-width here is unnecessarily complicated for what it is used for here (only org-ellipsis). It previously was used also for calculating the widths of the tags (next to last line) but this is done much better in buffer, with the complex fontification done by org-modern. And with this done in org-modern-mode-hook we can be quite sure that it will be done after all the tags have got their final appearance. This have worked well for me since yesterday 😀.

from org-modern.

minad avatar minad commented on August 20, 2024

Thanks. Yes, something like this is the plan.

from org-modern.

protesilaos avatar protesilaos commented on August 20, 2024

@andersjohansson Notwithstanding org-modern, is it feasible to rekindle that mailing list thread? I feel this should be a standard Org feature, though I understand if it is very difficult to do upstream.

from org-modern.

minad avatar minad commented on August 20, 2024

@protesilaos I am not sure if adjustments like this should be part of Org itself. As of now Org does not come with any such more intrusive text property adjustments and assumes that everything is fixed pitch, which is an acceptable assumption in my opinion. However maybe opinion is changing there? There is also the question if Org should try to pixel-align tables. Do you know if there are plans to add this upstream, then I don't have to do anything here?

from org-modern.

protesilaos avatar protesilaos commented on August 20, 2024

Personally, I am perfectly happy with Org's current assumptions. It's
just that people think of it as a bug, which is why I asked if it would
be worth discussing upstream.

More generally, this is not an Org bug. My understanding is that it is
how proportionately spaced fonts reduce the width of the spacing
characters (same principle for varying face :heights).

I tried a quick-n-dirty hack once of making spaces monospaced by abusing
whitespace-mode: it made the use of variable-pitch viable even for
programming. But yeah, that is fragile.

from org-modern.

minad avatar minad commented on August 20, 2024

(Accidentially closed)

from org-modern.

minad avatar minad commented on August 20, 2024

Closing. I am actually happy with not aligning tags to the right. In contrast, better table aligning is a more important issue.

from org-modern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.