Find file
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (58 sloc) 2.3 KB
;;; mc-edit-lines.el
;; Copyright (C) 2012 Magnar Sveen
;; Author: Magnar Sveen <>
;; Keywords: editing cursors
;; 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
;; 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 <>.
;;; Commentary:
;; This file contains functions to add multiple cursors to consecutive lines
;; given an active region.
;; Please see multiple-cursors.el for more commentary.
;;; Code:
(require 'multiple-cursors-core)
(defun mc/edit-lines ()
"Add one cursor to each line of the active region.
Starts from mark and moves in straight down or up towards the
line point is on."
(when (not (use-region-p))
(error "Mark a set of lines first."))
(let* ((col (current-column))
(point-line (line-number-at-pos))
(mark-line (progn (exchange-point-and-mark) (line-number-at-pos)))
(direction (if (< point-line mark-line) :up :down)))
(when (and (eq direction :up) (bolp))
(forward-line -1)
(move-to-column col))
(while (not (eq (line-number-at-pos) point-line))
(if (eq direction :up) (forward-line -1) (forward-line 1))
(move-to-column col))
(defun mc/edit-ends-of-lines ()
"Add one cursor to the end of each line in the active region."
(mc/execute-command-for-all-fake-cursors 'end-of-line)
(defun mc/edit-beginnings-of-lines ()
"Add one cursor to the beginning of each line in the active region."
(mc/execute-command-for-all-fake-cursors 'beginning-of-line)
(provide 'mc-edit-lines)
;;; mc-edit-lines.el ends here