Skip to content

Instantly share code, notes, and snippets.

@jackcviers
Last active December 17, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackcviers/5595896 to your computer and use it in GitHub Desktop.
Save jackcviers/5595896 to your computer and use it in GitHub Desktop.
kill-line-yank-newline copies the current line and inserts a duplicate of that line after the current line, with the parts of the import expression after the cursor deleted.. Useful for adding additional imports of the same package in languages such as java and scala.
;; Copyright (C) 2013 Jack Viers
;; Author: Jack Viers <jackcviers@gmail.com>
;; This file is not part of GNU Emacs.
(defun kill-line-yank-newline ()
(interactive)
(let ((beg (line-beginning-position)) (end (line-end-position)) (name (buffer-name)) (col (current-column)))
(end-of-line)
(newline)
(beginning-of-line)
(insert-buffer-substring name beg end)
(move-to-column col t)
(unless (eolp) (kill-sexp))))

kill-line-yank-newline

Documentation

kill-line-yank-newline -- copies the current line and inserts the copy on a newline, moving the cursor to point where it was on the previous line, and kills the next sexp (char to end of line, word-separator to end of line, etc).

It is extremely useful for things like adding a new import from the same package as the import on the previous line in languages such as Java or Scala.

I recommend binding it to an easy to remember key-binding, like C-y C-y.

Installation

Add the kill-line-yank-newline.el to your .emacs or other initialization file, or place the kill-line-yank-newline.el file somewhere in your emacs path and load it:

(load-file "/path/to/dir/containing/kill-line-yank-newline/kill-line-yank-newline.el")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment