summaryrefslogtreecommitdiff
path: root/snakemake-mode.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-06-03 01:10:43 -0400
committerKyle Meyer <kyle@kyleam.com>2015-06-03 01:10:43 -0400
commitc6765aae716722928ce03d00ccb0421088075a77 (patch)
tree2b69a50cf4e78d53fceaf6d6279e2ce8054493f2 /snakemake-mode.el
parent3ce395e2665d120d622b200636e65fbe47105f42 (diff)
downloadsnakemake-mode-c6765aae716722928ce03d00ccb0421088075a77.tar.gz
Coexist with Python mode Imenu items
Diffstat (limited to 'snakemake-mode.el')
-rw-r--r--snakemake-mode.el39
1 files changed, 29 insertions, 10 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el
index 5eeefb7..4a20236 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -321,6 +321,33 @@ command."
("subworkflow" (user-error "Cannot compile a subworkflow"))))))
+;;; Imenu
+
+(defun snakemake-imenu-create-index ()
+ "Create Imenu index for rule blocks.
+If `python-imenu-create-index' returns a non-nil value, also
+include these results and append a \"(rule)\" to the index
+label."
+ (let ((py-index (python-imenu-create-index))
+ (sm-index (snakemake--imenu-build-rule-index)))
+ (if py-index
+ (append (mapcar (lambda (x)
+ (cons (concat (car x) " (rule)") (cdr x)))
+ sm-index)
+ py-index)
+ sm-index)))
+
+(defun snakemake--imenu-build-rule-index ()
+ (goto-char (point-min))
+ (let (index)
+ (while (re-search-forward snakemake-rule-or-subworkflow-line-re nil t)
+ (push (cons (match-string-no-properties 2)
+ (save-excursion (beginning-of-line)
+ (point-marker)))
+ index))
+ index))
+
+
;;; Mode
(defvar snakemake-mode-map
@@ -337,16 +364,6 @@ command."
(,snakemake-builtin-function-re 1 font-lock-builtin-face)
(,snakemake-field-key-indented-re 1 font-lock-type-face)))
-(defun snakemake-set-imenu-generic-expression ()
- "Extract rule names for `imenu' index."
- ;; Disable `python-info-current-defun'
- (setq imenu-extract-index-name-function nil)
- (setq imenu-create-index-function 'imenu-default-create-index-function)
- (setq imenu-generic-expression
- `((nil ,snakemake-rule-or-subworkflow-line-re 2))))
-
-(add-hook 'snakemake-mode-hook 'snakemake-set-imenu-generic-expression)
-
;;;###autoload
(define-derived-mode snakemake-mode python-mode "Snakemake"
"Mode for editing Snakemake files.
@@ -355,6 +372,8 @@ command."
Type \\[snakemake-compile-rule] to run Snakemake with the rule of
the block at point as the target.
\n\\{snakemake-mode-map}"
+ (set (make-local-variable 'imenu-create-index-function)
+ #'snakemake-imenu-create-index)
(set (make-local-variable 'indent-line-function) 'snakemake-indent-line)
(set (make-local-variable 'font-lock-defaults)
`(,(append snakemake-font-lock-keywords python-font-lock-keywords)))