Skip to content

Commit

Permalink
Merge branch 'develop' (v0.41.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Jan 2, 2015
2 parents a371665 + 821a185 commit 044cf83
Show file tree
Hide file tree
Showing 5 changed files with 972 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ for more information.

# Learning Spacemacs

## Evil-tutor

Press <kbd>SPC h T</kbd> to start the Vimtutor adapted for Evil.

## The leader key

Spacemacs key bindings use a leader key which is set by default to
Expand Down
4 changes: 3 additions & 1 deletion core/spacemacs-mode.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(setq message-log-max 16384)
(defconst emacs-start-time (current-time))

(defconst spacemacs-version "0.40.1"
(require 'subr-x)

(defconst spacemacs-version "0.41.0"
"Spacemacs version.")

(defconst spacemacs-min-version "24.3"
Expand Down
11 changes: 11 additions & 0 deletions spacemacs/extensions.el
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
centered-cursor
emoji-cheat-sheet
evil-plugins
evil-tutor
helm-rcirc
helm-spacemacs
neotree
Expand All @@ -21,6 +22,16 @@

;; Initialize the extensions

(defun spacemacs/init-evil-tutor ()
(use-package evil-tutor
:commands (evil-tutor/start
evil-tutor/resume)
:init
(progn
(setq evil-tutor-working-directory
(concat spacemacs-cache-directory ".tutor/"))
(evil-leader/set-key "hT" 'evil-tutor/start))))

(defun spacemacs/init-centered-cursor ()
(use-package centered-cursor-mode
:commands global-centered-cursor-mode
Expand Down
125 changes: 125 additions & 0 deletions spacemacs/extensions/evil-tutor/evil-tutor.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
;;; evil-tutor.el --- Vimtutor adapted to Evil and wrapped in a mode

;; Copyright (C) 2015 syl20bnr
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; Keywords: convenience editing evil
;; Created: 1 Jan 2015
;; Version: 0.1
;; Package-Requires: ((evil "1.0.9"))
;; URL: https://github.com/syl20bnr/evil-tutor

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'evil)

(defcustom evil-tutor-working-directory
(file-name-as-directory (expand-file-name ".tutor" user-emacs-directory))
"The directory where to create working files."
:type 'string
:group 'evil)

(define-derived-mode evil-tutor-mode text-mode "evil-tutor"
"Major mode for evil-tutor.")

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

;;;###autoload
(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)

(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
found file is visited instead of creating a brand new buffer.
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)))
(message "load: %s" (symbol-file 'evil-tutor-mode))
(if previous-file
(find-file-literally previous-file)
(let* ((date (format-time-string "%d%m%Y"))
(working-file-name (format "evil-tutor-%s.txt" date))
(tutor-file (concat (file-name-directory (symbol-file
'evil-tutor-mode))
"tutor.txt")))
(switch-to-buffer (get-buffer-create "working-file-name"))
(set-visited-file-name (concat evil-tutor-working-directory
working-file-name))
(insert-file-contents tutor-file)
(make-directory evil-tutor-working-directory 'parents)
(save-buffer 0)))))

(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."
(when files
(catch 'break
(dolist (f files)
(if (string= ".txt" (file-name-extension f 'period))
(throw 'break f)))
nil)))

(defun evil-tutor/goto-next-lesson (&optional arg)
"Move the next lesson.
If ARG is nil then move to the next lesson,
If ARG is positive then move the ARGth version after the current one,
If ARG is negative then move the ARGth version before the current one."
(interactive "p")
(let ((i 0)
(regexp "^~.*~$")
(count (if arg (abs arg) 1))
(recenter-positions '(top)))
(dotimes (i count)
(if (or (not arg)
(> arg 0))
(re-search-forward regexp (buffer-end 1) 'noerror)
(re-search-backward regexp (buffer-end -1) 'noerror)))
(beginning-of-line)
(next-line)
(recenter-top-bottom)))

(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)))

(provide 'evil-tutor)

;;; evil-tutor.el ends here
Loading

0 comments on commit 044cf83

Please sign in to comment.