From 0dab4eb051b9c27ff05ec53a0458132b685b16f9 Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Sat, 14 Oct 2017 00:31:57 +0200 Subject: [PATCH] Add counsel function to easily open org files in org directory --- emacs/.emacs.d/init.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index 36bd2e5..81019f2 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -1,11 +1,19 @@ (package-initialize) (require 'package) +(require 'cl) ;; Nope function (defun nope () (interactive) (message "Nope!")) +;; Helper function +(defun string-ends-with-p (string suffix) + "Return t if STRING ends with SUFFIX." + (and (string-match (rx-to-string `(: ,suffix eos) t) + string) + t)) + ;; Quote (setq initial-scratch-message (concat ";; Simplicity and elegance are unpopular because\n" @@ -174,13 +182,23 @@ (use-package heroku-theme :ensure t) +;; Open .org files in org directory +(defun my/counsel-org-agenda () + "Open .org files in org directory" + (interactive) + (find-file (concat (file-name-as-directory org-directory) + (ivy-read "Org files: " + (remove-if-not + (lambda (e) (string-ends-with-p e ".org")) + (directory-files org-directory)))))) + ;; Org-mode (use-package org :ensure t :config (setq org-directory "~/org") (setq org-agenda-files "~/org/agenda") - (global-set-key (kbd "") 'org-agenda) + (global-set-key (kbd "") 'my/counsel-org-agenda) (setq org-todo-keywords '((sequence "TODO" "WORKING" "BLOCKED" "REVIEW" "|" "ABANDONED" "DONE"))) (setq org-todo-keyword-faces '(("TODO" . "firebrick2")