Add navigation functions for end-of-line and beginning-of-line
This commit is contained in:
parent
378ef3d590
commit
a709f502f8
4 changed files with 130 additions and 1 deletions
|
@ -168,6 +168,12 @@ unit-test-oni-conf:
|
|||
- package
|
||||
script: make unit-test-oni-conf TEST_ARCHIVE=$(realpath bin/)
|
||||
|
||||
unit-test-oni-core:
|
||||
stage: unit-test
|
||||
dependencies:
|
||||
- package
|
||||
script: make unit-test-oni-core TEST_ARCHIVE=$(realpath bin/)
|
||||
|
||||
unit-test-oni-elisp:
|
||||
stage: unit-test
|
||||
dependencies:
|
||||
|
@ -254,6 +260,13 @@ integration-test-oni-browse-url:
|
|||
- package
|
||||
script: make integration-test-oni-browse-url TEST_ARCHIVE=$(realpath bin/)
|
||||
|
||||
integration-test-oni-core:
|
||||
stage: integration-test
|
||||
image: registry.gitlab.com/ryuslash/emacs-config
|
||||
dependencies:
|
||||
- package
|
||||
script: make integration-test-oni-core TEST_ARCHIVE=$(realpath bin/)
|
||||
|
||||
integration-test-oni-cpp:
|
||||
stage: integration-test
|
||||
image: registry.gitlab.com/ryuslash/emacs-config
|
||||
|
|
29
oni-core.el
29
oni-core.el
|
@ -4,7 +4,7 @@
|
|||
|
||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||
;; Keywords: local
|
||||
;; Version: 2020.0225.095408
|
||||
;; Version: 2020.0407.015402
|
||||
;; Package-Requires: (oni-data-dir expand-region multiple-cursors embrace helpful)
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
|
@ -53,6 +53,31 @@
|
|||
"Create the autosave directory if doesn't exist."
|
||||
(mkdir oni-core--auto-save-directory t))
|
||||
|
||||
(defun oni-core-move-beginning-of-dwim ()
|
||||
"Move to beginning of line either after indentation or before."
|
||||
(interactive)
|
||||
(let ((start (point)))
|
||||
(back-to-indentation)
|
||||
(unless (/= start (point))
|
||||
(move-beginning-of-line 1))))
|
||||
|
||||
(defun oni-core-move-end-of-dwim ()
|
||||
"Move to end of line, either before any comments or after."
|
||||
(interactive)
|
||||
(let ((start (point))
|
||||
(eolpos (line-end-position)))
|
||||
(beginning-of-line)
|
||||
(if (and comment-start
|
||||
(not (looking-at (regexp-quote comment-start)))
|
||||
(comment-search-forward eolpos t))
|
||||
(progn
|
||||
(search-backward-regexp (concat "[^ \t" comment-start "]"))
|
||||
(forward-char)
|
||||
(when (or (bolp)
|
||||
(= start (point)))
|
||||
(end-of-line)))
|
||||
(end-of-line))))
|
||||
|
||||
(add-to-list 'auto-save-file-name-transforms
|
||||
`(".*" ,oni-core--auto-save-directory t)
|
||||
:append)
|
||||
|
@ -108,6 +133,8 @@
|
|||
(global-set-key (kbd "C-c (") 'embrace-commander)
|
||||
(global-set-key (kbd "C-x M-f") 'ffap)
|
||||
(global-set-key (kbd "C-x C-b") 'ibuffer-jump)
|
||||
(global-set-key [remap move-beginning-of-line] #'oni-core-move-beginning-of-dwim)
|
||||
(global-set-key [remap move-end-of-line] #'oni-core-move-end-of-dwim)
|
||||
|
||||
(global-set-key [remap describe-function] 'helpful-callable)
|
||||
(global-set-key [remap describe-key] 'helpful-key)
|
||||
|
|
28
test/integration/oni-core.bats
Normal file
28
test/integration/oni-core.bats
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
@test "Opening emacs loads oni-core" {
|
||||
run emacs -batch -l package -f package-initialize \
|
||||
-eval "(prin1 (featurep 'oni-core))"
|
||||
|
||||
echo "$output"
|
||||
|
||||
[[ "$output" == *"t" ]]
|
||||
}
|
||||
|
||||
@test "C-a is bound to oni-core-move-to-beginning-of-dwim" {
|
||||
run emacs -batch -l package -f package-initialize \
|
||||
-eval "(prin1 (key-binding (kbd \"C-a\")))"
|
||||
|
||||
echo "$output"
|
||||
|
||||
[[ "$output" == *"oni-core-move-beginning-of-dwim" ]]
|
||||
}
|
||||
|
||||
@test "C-e is bound to oni-core-move-to-end-of-dwim" {
|
||||
run emacs -batch -l package -f package-initialize \
|
||||
-eval "(prin1 (key-binding (kbd \"C-e\")))"
|
||||
|
||||
echo "$output"
|
||||
|
||||
[[ "$output" == *"oni-core-move-end-of-dwim" ]]
|
||||
}
|
61
test/oni-core-test.el
Normal file
61
test/oni-core-test.el
Normal file
|
@ -0,0 +1,61 @@
|
|||
(require 'oni-core)
|
||||
|
||||
(ert-deftest oni-core-move-beginning-of-dwim-moves-to-beginning-of-indentation ()
|
||||
"Test that ‘oni-core-move-beginning-of-dwim’ moves to the beginning of indentation."
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(insert "(defun test-defun ()\n \"Just testing a function\")")
|
||||
(goto-char (point-max))
|
||||
(oni-core-move-beginning-of-dwim)
|
||||
(should (equal 24 (point)))))
|
||||
|
||||
(ert-deftest oni-core-move-beginning-of-dwim-moves-to-beginning-of-line ()
|
||||
"Test that ‘oni-core-move-beginning-of-dwim’ moves to the beginning of the line."
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(insert "(defun test-defun ()\n \"Just testing a function\")")
|
||||
(goto-char (point-max))
|
||||
(oni-core-move-beginning-of-dwim)
|
||||
(oni-core-move-beginning-of-dwim)
|
||||
(should (equal 22 (point)))))
|
||||
|
||||
(ert-deftest oni-core-move-beginning-of-dwim-moves-to-beginning-of-indentation-again ()
|
||||
"Test that ‘oni-core-move-beginning-of-dwim’ moves to the beginning of indentation again."
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(insert "(defun test-defun ()\n \"Just testing a function\")")
|
||||
(goto-char (point-max))
|
||||
(oni-core-move-beginning-of-dwim)
|
||||
(oni-core-move-beginning-of-dwim)
|
||||
(oni-core-move-beginning-of-dwim)
|
||||
(should (equal 24 (point)))))
|
||||
|
||||
(ert-deftest oni-core-move-end-of-dwim-moves-to-end-of-code ()
|
||||
"Test that ‘oni-core-move-end-of-dwim’ moves to the end of the code before a comment."
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(insert "(defun test-defun () ;; Just testing\n \"Just testing a function\")")
|
||||
(goto-char (point-min))
|
||||
(oni-core-move-end-of-dwim)
|
||||
(should (equal 21 (point)))))
|
||||
|
||||
(ert-deftest oni-core-move-end-of-dwim-moves-to-end-of-line ()
|
||||
"Test that ‘oni-core-move-end-of-dwim’ moves to the end of the line."
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(insert "(defun test-defun () ;; Just testing\n \"Just testing a function\")")
|
||||
(goto-char (point-min))
|
||||
(oni-core-move-end-of-dwim)
|
||||
(oni-core-move-end-of-dwim)
|
||||
(should (equal 38 (point)))))
|
||||
|
||||
(ert-deftest oni-core-move-end-of-dwim-moves-to-end-of-code-again ()
|
||||
"Test that ‘oni-core-move-end-of-dwim’ moves to the end of the code before a comment again."
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(insert "(defun test-defun () ;; Just testing\n \"Just testing a function\")")
|
||||
(goto-char (point-min))
|
||||
(oni-core-move-end-of-dwim)
|
||||
(oni-core-move-end-of-dwim)
|
||||
(oni-core-move-end-of-dwim)
|
||||
(should (equal 21 (point)))))
|
Loading…
Reference in a new issue