ivy: use post-init to add hook for org-ctrl-c-ctrl-c

This commit is contained in:
syl20bnr 2018-01-06 11:51:19 -05:00
parent fcf33be0f7
commit 14b206492b
4 changed files with 42 additions and 40 deletions

View File

@ -301,6 +301,43 @@ To prevent this error we just wrap `describe-mode' to defeat the
(unless (eq ivy-exit 'done)
(swiper--cleanup)
(swiper--add-overlays (ivy--regex ivy-text)))))))
;; org
;; see https://github.com/abo-abo/swiper/issues/177
(defun spacemacs//counsel-org-ctrl-c-ctrl-c-org-tag ()
"Hook for `org-ctrl-c-ctrl-c-hook' to use `counsel-org-tag'."
(if (save-excursion (beginning-of-line) (looking-at "[ \t]*$"))
(or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
(user-error "C-c C-c can do nothing useful at this location"))
(let* ((context (org-element-context))
(type (org-element-type context)))
(case type
;; When at a link, act according to the parent instead.
(link (setq context (org-element-property :parent context))
(setq type (org-element-type context)))
;; Unsupported object types: refer to the first supported
;; element or object containing it.
((bold code entity export-snippet inline-babel-call inline-src-block
italic latex-fragment line-break macro strike-through subscript
superscript underline verbatim)
(setq context
(org-element-lineage
context '(radio-target paragraph verse-block table-cell)))))
;; For convenience: at the first line of a paragraph on the
;; same line as an item, apply function on that item instead.
(when (eq type 'paragraph)
(let ((parent (org-element-property :parent context)))
(when (and (eq (org-element-type parent) 'item)
(= (line-beginning-position)
(org-element-property :begin parent)))
(setq context parent type 'item))))
;; Act according to type of element or object at point.
(case type
((headline inlinetask)
(save-excursion (goto-char (org-element-property :begin context))
(call-interactively 'counsel-org-tag)) t)))))
;; Ivy

View File

@ -21,6 +21,7 @@
ivy
ivy-hydra
(ivy-spacemacs-help :location local)
org
persp-mode
projectile
smex
@ -295,6 +296,9 @@
"h r" 'ivy-spacemacs-help-docs
"h t" 'ivy-spacemacs-help-toggles)))
(defun ivy/post-init-org ()
(add-hook 'org-ctrl-c-ctrl-c-hook 'spacemacs//counsel-org-ctrl-c-ctrl-c-org-tag))
(defun ivy/init-swiper ()
(use-package swiper
:config

View File

@ -44,37 +44,3 @@
(defun spacemacs//evil-org-mode ()
(evil-org-mode)
(evil-normalize-keymaps))
(defun spacemacs//org-ctrl-c-ctrl-c-counsel-org-tag ()
"Hook for `org-ctrl-c-ctrl-c-hook' to use `counsel-org-tag'."
(if (save-excursion (beginning-of-line) (looking-at "[ \t]*$"))
(or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
(user-error "C-c C-c can do nothing useful at this location"))
(let* ((context (org-element-context))
(type (org-element-type context)))
(case type
;; When at a link, act according to the parent instead.
(link (setq context (org-element-property :parent context))
(setq type (org-element-type context)))
;; Unsupported object types: refer to the first supported
;; element or object containing it.
((bold code entity export-snippet inline-babel-call inline-src-block
italic latex-fragment line-break macro strike-through subscript
superscript underline verbatim)
(setq context
(org-element-lineage
context '(radio-target paragraph verse-block table-cell)))))
;; For convenience: at the first line of a paragraph on the
;; same line as an item, apply function on that item instead.
(when (eq type 'paragraph)
(let ((parent (org-element-property :parent context)))
(when (and (eq (org-element-type parent) 'item)
(= (line-beginning-position)
(org-element-property :begin parent)))
(setq context parent type 'item))))
;; Act according to type of element or object at point.
(case type
((headline inlinetask)
(save-excursion (goto-char (org-element-property :begin context))
(call-interactively 'counsel-org-tag)) t)))))

View File

@ -344,12 +344,7 @@ Will work on both org-mode and any mode that accepts plain html."
(org-eval-in-calendar '(calendar-backward-year 1))))
(define-key org-read-date-minibuffer-local-map (kbd "M-J")
(lambda () (interactive)
(org-eval-in-calendar '(calendar-forward-year 1)))))
;; Default `org-set-tags' does not work well with ivy.
(when (configuration-layer/layer-usedp 'ivy)
(add-hook 'org-ctrl-c-ctrl-c-hook
'spacemacs//org-ctrl-c-ctrl-c-counsel-org-tag)))))
(org-eval-in-calendar '(calendar-forward-year 1))))))))
(defun org/init-org-agenda ()
(use-package org-agenda