Skip to content

Commit fefadd6

Browse files
committed
Implement moving defun command
This also implements mark-defun command.
1 parent decdf8a commit fefadd6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

elixir-mode.el

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,32 @@ just return nil."
467467
(backward-char)
468468
(fill-region (point) (mark))))
469469

470+
(defun elixir-beginning-of-defun (&optional arg)
471+
(interactive "p")
472+
(let ((command last-command)
473+
(regexp (concat "^\\s-*" (elixir-rx builtin-declaration)))
474+
case-fold-search)
475+
(while (and (re-search-backward regexp nil t (or arg 1))
476+
(elixir-syntax-in-string-or-comment-p)))
477+
(goto-char (line-beginning-position))))
478+
479+
(defun elixir-end-of-defun ()
480+
(interactive)
481+
(goto-char (line-beginning-position))
482+
(if (re-search-forward "\\_<do:" (line-end-position) t)
483+
(goto-char (line-end-position))
484+
(goto-char (line-end-position))
485+
(let ((level (save-excursion
486+
(elixir-beginning-of-defun)
487+
(current-indentation)))
488+
finish)
489+
(while (and (not finish) (re-search-forward "^\\s-*\\_<end\\_>" nil t))
490+
(when (and (not (elixir-syntax-in-string-or-comment-p))
491+
(= (current-indentation) level))
492+
(setq finish t)))
493+
(when (looking-back "^\\s-*\\_<end" (line-beginning-position))
494+
(forward-line 1)))))
495+
470496
(easy-menu-define elixir-mode-menu elixir-mode-map
471497
"Elixir mode menu."
472498
'("Elixir"
@@ -491,6 +517,10 @@ just return nil."
491517
#'elixir-syntax-propertize-function)
492518
(set (make-local-variable 'imenu-generic-expression)
493519
elixir-imenu-generic-expression)
520+
521+
(set (make-local-variable 'beginning-of-defun-function) #'elixir-beginning-of-defun)
522+
(set (make-local-variable 'end-of-defun-function) #'elixir-end-of-defun)
523+
494524
(smie-setup elixir-smie-grammar 'verbose-elixir-smie-rules
495525
:forward-token 'elixir-smie-forward-token
496526
:backward-token 'elixir-smie-backward-token))

0 commit comments

Comments
 (0)