* A `mark-line' function
@ 2010-04-27 11:21 David House
0 siblings, 0 replies; only message in thread
From: David House @ 2010-04-27 11:21 UTC (permalink / raw)
To: Emacs Devel
[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]
Hi,
I've written a mark-line function that behaves analogously to
mark-word, mark-paragraph etc. This has always seemed like a silly
omission to me.
Here are some examples (! indicates position of point, # indicates
position of mark):
Original text:
foo
bar
ba!z
quux
With M-x mark-line:
foo
bar
!baz#
quux
With C-u 2 M-x mark-line instead:
foo
bar
!baz
quux#
With C-u -1 M-x mark-line instead:
foo
#bar
!baz
quux
It is in fact exactly the source of mark-paragraph using forward-line
and previous-line instead of forward-paragraph and backward-paragraph
respectively.
I have attached two patches; one contains the definition of the
function and the other the binding (M-n), in case it is decided that a
binding isn't wished for, or a different binding would be better. The
patches are in "git diff" format. I realise this probably isn't the
right format for them to be in but I was unsure about what exactly is
needed. If it would be helpful to have the patches in an alternative
format please let me know.
I look forward to your feedback. Thanks,
-David
[-- Attachment #2: mark-line.patch --]
[-- Type: text/x-patch, Size: 1313 bytes --]
diff --git a/lisp/simple.el b/lisp/simple.el
index f609755..a6232d7 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3970,6 +3970,36 @@ for it.")
(goto-char position)
(switch-to-buffer buffer)))
\f
+(defun mark-line (&optional arg allow-extend)
+ "Put point at beginning of this line, mark at end.
+The line marked is the one that contains point or follows point.
+
+With argument ARG, puts mark at end of a following line, so that
+the number of lines marked equals ARG.
+
+If ARG is negative, point is put at end of this line, mark is put
+at beginning of this or a previous line.
+
+Interactively, if this command is repeated or (in Transient Mark
+mode) if the mark is active, it marks the next ARG lines after
+the ones already marked."
+ (interactive "p\np")
+ (unless arg (setq arg 1))
+ (when (zerop arg)
+ (error "Cannot mark zero lines"))
+ (cond ((and allow-extend
+ (or (and (eq last-command this-command) (mark t))
+ (and transient-mark-mode mark-active)))
+ (set-mark
+ (save-excursion
+ (goto-char (mark))
+ (forward-line arg)
+ (point))))
+ (t
+ (forward-line arg)
+ (push-mark nil t t)
+ (previous-line arg))))
+
(defcustom next-line-add-newlines nil
"If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
:type 'boolean
[-- Attachment #3: mark-line-binding.patch --]
[-- Type: text/x-patch, Size: 452 bytes --]
diff --git a/lisp/bindings.el b/lisp/bindings.el
index a7f6643..07dbc0d 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -822,6 +822,7 @@ or \\[semantic-mode]")))))
(define-key ctl-x-map "\C-@" 'pop-global-mark)
(define-key ctl-x-map [?\C- ] 'pop-global-mark)
+(define-key global-map "\M-n" 'mark-line)
(define-key global-map "\C-n" 'next-line)
(define-key global-map "\C-p" 'previous-line)
(define-key ctl-x-map "\C-n" 'set-goal-column)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-04-27 11:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-27 11:21 A `mark-line' function David House
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.