emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Benjamin Andresen <benny@in-ulm.de>
To: emacs-orgmode@gnu.org
Subject: Dynamically adjusti tags position
Date: Thu, 09 Jul 2009 02:35:31 +0200	[thread overview]
Message-ID: <87zlbewv58.fsf@in-ulm.de> (raw)

hey there,

I wrote a bit of code that allows me to have the tags always at the
utmost right position in the file... I often have windows that are
bigger than the standard 80 characters wide default and I dislike seeing
the tags in the middle of the window.

I started doing this and found out that adjusting the tags every time I
resize a window breaks tracking org-mode files with git. If the last
window is just a bit smaller than last time, the complete line will be
shown as a diff. Therefor hooks are used to reset the column variable to
1 so that git tracking still works.

If anyone wants to use this or want to look over it if I could do this
smarter, I'm very happy.

If the response is positive I'll clean it up a bit and maybe it is worth
a contribution or a worg page. :-)

best regards,

(defcustom ba/org-adjust-tags-column t)
(setq ba/org-adjust-tags-column t)

(defun ba/org-adjust-tags-column-reset-tags ()
  (when (and
         (not (string= (buffer-name) "*Remember*"))
         (eql major-mode 'org-mode))
    (let ((b-m-p (buffer-modified-p)))
      (condition-case nil
            (goto-char (point-min))
            (command-execute 'outline-next-visible-heading)
            ;; disable (message) that org-set-tags generates
            (flet ((message (&rest ignored) nil))
              (org-set-tags 1 t))
            (set-buffer-modified-p b-m-p))
        (error nil)))))

(defun ba/org-adjust-tags-column-now ()
  (set (make-local-variable 'org-tags-column)
       (- (- (window-width) 3)))

(defun ba/org-adjust-tags-column-maybe ()
  (when ba/org-adjust-tags-column

(defun ba/org-adjust-tags-column-before-save ()
  (when ba/org-adjust-tags-column
     (setq org-tags-column 1)

(defun ba/org-adjust-tags-column-after-save ()
  (set-buffer-modified-p nil))

; automatically align tags on right-hand side
(add-hook 'window-configuration-change-hook
(add-hook 'before-save-hook 'ba/org-adjust-tags-column-before-save)
(add-hook 'after-save-hook 'ba/org-adjust-tags-column-after-save)

             reply	other threads:[~2009-07-09  0:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-09  0:35 Benjamin Andresen [this message]
2009-07-09  1:49 ` Dynamically adjusti tags position 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:

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87zlbewv58.fsf@in-ulm.de \
    --to=benny@in-ulm.de \
    --cc=emacs-orgmode@gnu.org \


* 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 public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).