emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Dynamically adjusti tags position
@ 2009-07-09  0:35 Benjamin Andresen
  2009-07-09  1:49 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Benjamin Andresen @ 2009-07-09  0:35 UTC (permalink / raw)
  To: emacs-orgmode

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,
benny

(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
          (save-excursion
            (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)))
  (ba/org-adjust-tags-column-reset-tags))

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

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

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

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Dynamically adjusti tags position
  2009-07-09  0:35 Dynamically adjusti tags position Benjamin Andresen
@ 2009-07-09  1:49 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2009-07-09  1:49 UTC (permalink / raw)
  To: Benjamin Andresen; +Cc: emacs-orgmode

Hi Benjamin,

Benjamin Andresen <benny@in-ulm.de> writes:

> 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 see...

> 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.

Maybe a safer solution would be to use an overlay for displaying tags.

This way you don't need to worry that changes in the tag display will
be seen as a diff.  But maybe there are already too many overlays on 
an Org page...

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

I tried it.  Just replace defcustom by setq, because the defcustom
definition is wrong here.

It works very well for small files, but the hooks are slowing down Emacs
display for big files (i.e. the 400k Org file in which I spend my daily
life.)  Perhaps using overlays would also fix this...

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

Definitely worth a new "Org hacks" entry!

  http://orgmode.org/worg/org-hacks.php

Just send me your username on repo.or.cz.

Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-07-09  1:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-09  0:35 Dynamically adjusti tags position Benjamin Andresen
2009-07-09  1:49 ` Bastien

Code repositories for project(s) associated with this public inbox

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

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).