From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Andresen Subject: Dynamically adjusti tags position Date: Thu, 09 Jul 2009 02:35:31 +0200 Message-ID: <87zlbewv58.fsf@in-ulm.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MOhcm-0001tZ-FK for emacs-orgmode@gnu.org; Wed, 08 Jul 2009 20:36:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MOhch-0001rU-EB for emacs-orgmode@gnu.org; Wed, 08 Jul 2009 20:36:31 -0400 Received: from [199.232.76.173] (port=33606 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MOhch-0001rL-69 for emacs-orgmode@gnu.org; Wed, 08 Jul 2009 20:36:27 -0400 Received: from mail.in-ulm.de ([217.10.8.10]:46732) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MOhcg-0000RM-K9 for emacs-orgmode@gnu.org; Wed, 08 Jul 2009 20:36:26 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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)