From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arun Persaud Subject: Re: feature request for empty blocks in customized agenda Date: Sat, 13 Jun 2015 16:57:30 -0700 Message-ID: <557CC36A.90305@lbl.gov> References: <557C8E8D.9020400@lbl.gov> <871thfnrh1.fsf@kmlap.domain.org> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3vIx-0005Sh-W6 for emacs-orgmode@gnu.org; Sat, 13 Jun 2015 19:57:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3vIu-00018p-QX for emacs-orgmode@gnu.org; Sat, 13 Jun 2015 19:57:39 -0400 Received: from fe2.lbl.gov ([128.3.41.134]:22941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3vIu-00018l-H0 for emacs-orgmode@gnu.org; Sat, 13 Jun 2015 19:57:36 -0400 Received: by pacyx8 with SMTP id yx8so42685247pac.2 for ; Sat, 13 Jun 2015 16:57:34 -0700 (PDT) In-Reply-To: <871thfnrh1.fsf@kmlap.domain.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Kyle Meyer Cc: emacs-orgmode Hi > I'm not sure if someone will find this feature useful enough to > incorporate. However, even if it doesn't get added, I think you can get > the behavior you want using org-agenda-finalize-hook. Hopefully the > snippet below can be a useful starting point. > > #+begin_src elisp > (defun org-agenda-delete-empty-blocks () > "Remove empty agenda blocks. > A block is identified as empty if there are fewer than 2 > non-empty lines in the block (excluding the line with > `org-agenda-block-separator' characters)." > (when org-agenda-compact-blocks > (user-error "Cannot delete empty compact blocks")) > (setq buffer-read-only nil) > (save-excursion > (goto-char (point-min)) > (let* ((blank-line-re "^\\s-*$") > (content-line-count (if (looking-at-p blank-line-re) 0 1)) > (start-pos (point)) > (block-re (format "%c\\{10,\\}" org-agenda-block-separator))) > (while (and (not (eobp)) (forward-line)) > (cond > ((looking-at-p block-re) > (when (< content-line-count 2) > (delete-region start-pos (1+ (point-at-bol)))) > (setq start-pos (point)) > (forward-line) > (setq content-line-count (if (looking-at-p blank-line-re) 0 1))) > ((not (looking-at-p blank-line-re)) > (setq content-line-count (1+ content-line-count))))) > (when (< content-line-count 2) > (delete-region start-pos (point-max))) > (goto-char (point-min)) > ;; The above strategy can leave a separator line at the beginning > ;; of the buffer. > (when (looking-at-p block-re) > (delete-region (point) (1+ (point-at-eol)))))) > (setq buffer-read-only t)) > > (add-hook 'org-agenda-finalize-hook #'org-agenda-delete-empty-blocks) > #+end_src a starting point seems to be an understatement ;) this seems to work exactly as intended. Thanks! Completely blanked out the use of any hooks, although it seems the obvious thing to do ;) Thanks again Arun