Skip to content

Commit

Permalink
Standard symbols naming and better README
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Jan 2, 2015
1 parent 8a88214 commit 28333d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
51 changes: 41 additions & 10 deletions README.md
@@ -1,28 +1,59 @@
# evil-tutor

Vimtutor adapted for Evil.
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**

M-x evil-tutor/start
- [evil-tutor](#evil-tutor)
- [Description](#description)
- [Quick start](#quick-start)
- [Install](#install)
- [Package manager](#package-manager)
- [Manually](#manually)
- [Acknowledgement](#acknowledgement)

This will create a working file in `evil-tutor-working-directory` (defaults
to `~/.emacs.d/.tutor`)
<!-- markdown-toc end -->

## Description

Vimtutor adapted for Evil and wrapped in a major mode.

Features:
- restore last working file
- fast navigation between lessons with `C-j` and `C-k`

This major-mode has been inspired by a [post][] on [/r/emacs][].
## Quick start

M-x evil-tutor-start

This will create a working file in `evil-tutor-working-directory` (defaults
to `~/.emacs.d/.tutor`)

## Install

The package _will be available soon_ in [MELPA][].
### Package manager

You can either install `evil-iedit-state` from [MELPA][] (_available soon_):

```
M-x package-install evil-tutor
```

Or add it to your `Cask` file:

If you have MELPA in `package-archives`, use
```elisp
(source melpa)
M-x package-install RET evil-tutor RET
(depends-on "evil-tutor")
```

If you don't, open `evil-tutor.el` in Emacs and call
`package-install-from-buffer`.
### Manually

Add `evil-tutor.el` to your load path. `evil-tutor` requires `evil` to be
installed.

## Acknowledgement

This major-mode has been inspired by a [post][] on [/r/emacs][].

[MELPA]: http://melpa.org/
[/r/emacs]: http://www.reddit.com/r/emacs/
Expand Down
24 changes: 12 additions & 12 deletions evil-tutor.el
Expand Up @@ -28,7 +28,7 @@

;; Vimtutor adapted for Evil.

;; M-x evil-tutor/start
;; M-x evil-tutor-start

;; This will create a working file in `evil-tutor-working-directory' (defaults
;; to `~/.emacs.d/.tutor')
Expand All @@ -51,21 +51,21 @@
"Major mode for evil-tutor.")

;;;###autoload
(defun evil-tutor/start ()
(defun evil-tutor-start ()
"Start a evil-tutor session."
(interactive)
(evil-tutor//restore-or-create-working-file)
(evil-tutor--restore-or-create-working-file)
(evil-tutor-mode)
(evil-mode))

;;;###autoload
(defalias 'evil-tutor/resume 'evil-tutor/start)
(defalias 'evil-tutor-resume 'evil-tutor-start)

(set-keymap-parent evil-tutor-mode-map text-mode-map)
(define-key evil-tutor-mode-map (kbd "C-j") 'evil-tutor/goto-next-lesson)
(define-key evil-tutor-mode-map (kbd "C-k") 'evil-tutor/goto-previous-lesson)
(define-key evil-tutor-mode-map (kbd "C-j") 'evil-tutor-goto-next-lesson)
(define-key evil-tutor-mode-map (kbd "C-k") 'evil-tutor-goto-previous-lesson)

(defun evil-tutor//restore-or-create-working-file ()
(defun evil-tutor--restore-or-create-working-file ()
"Create a new working buffer and save it in `evil-tutor-working-directory'.
If a working file already exists in `evil-tutor-working-directory' then the
Expand All @@ -75,7 +75,7 @@ For now the point location is not saved but this is a functionality which can
be handled by minor modes."
(let* ((files (if (file-exists-p evil-tutor-working-directory)
(directory-files evil-tutor-working-directory t nil t)))
(previous-file (evil-tutor//find-first-working-file files)))
(previous-file (evil-tutor--find-first-working-file files)))
(message "load: %s" (symbol-file 'evil-tutor-mode))
(if previous-file
(find-file-literally previous-file)
Expand All @@ -91,7 +91,7 @@ be handled by minor modes."
(make-directory evil-tutor-working-directory 'parents)
(save-buffer 0)))))

(defun evil-tutor//find-first-working-file (files)
(defun evil-tutor--find-first-working-file (files)
"Return the first saved working file or nil if there is no such file.
This function expects full path for each file in FILES."
Expand All @@ -102,7 +102,7 @@ This function expects full path for each file in FILES."
(throw 'break f)))
nil)))

(defun evil-tutor/goto-next-lesson (&optional arg)
(defun evil-tutor-goto-next-lesson (&optional arg)
"Move the next lesson.
If ARG is nil then move to the next lesson,
Expand All @@ -122,14 +122,14 @@ If ARG is negative then move the ARGth version before the current one."
(next-line)
(recenter-top-bottom)))

(defun evil-tutor/goto-previous-lesson (&optional arg)
(defun evil-tutor-goto-previous-lesson (&optional arg)
"Move to the previous lession.
If ARG is nil then move to the previous lesson.
If ARG is positive then move to the ARGth lesson before the current one."
(interactive "p")
;; -1 because we have to skip the current lesson
(evil-tutor/goto-next-lesson (- (if arg (- (abs arg)) -1) 1)))
(evil-tutor-goto-next-lesson (- (if arg (- (abs arg)) -1) 1)))

(provide 'evil-tutor)

Expand Down

0 comments on commit 28333d4

Please sign in to comment.