From: "Arni Magnusson" <arnima@hafro.is>
To: bug-gnu-emacs@gnu.org
Subject: bug#2887: Suggestions for simple.el
Date: Sat, 4 Apr 2009 13:32:03 -0000 (GMT) [thread overview]
Message-ID: <26172.194.144.135.59.1238851923.squirrel@www.hafro.is> (raw)
[-- Attachment #1: Type: text/plain, Size: 986 bytes --]
Dear Emacs maintainers,
I would like to suggest adding a few functions to the simple.el library. I
do this with hesitation - since I know the idea is to keep it simple and
let users write extensions to suit their preferences - but I believe a
large number of Emacs users would appreciate having access to these
functions out of the box.
I just finished teaching an Emacs workshop, where I ended up distributing
these functions to my colleagues, but I found it hard to explain whey
they're not already in simple.el.
Please see the attached file suggestions-simple.el. Instead of giving
detailed reasons for including each function, I have only briefly
commented on which functionality I'm extending, or which gap I'm bridging.
I have used these functions a lot, but I am sure the Emacs maintainers can
see ways to improve them in terms of robustness, speed, function names,
documentation, etc. I would be happy to discuss any further details with
you.
All the best,
Arni Magnusson
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: suggestions-simple.el --]
[-- Type: text/x-emacs-lisp; name="suggestions-simple.el", Size: 4086 bytes --]
;; simple::backward-kill-word
;; subr::backward-delete-char
(defun backward-delete-word (N) "Delete previous N words." (interactive "*p")(delete-word (- N)))
;; simple::kill-word
;; C::delete-char
(defun delete-word (N) "Delete following N words." (interactive "*p")
(delete-region (point)(save-excursion (forward-word N)(point))))
;; simple::kill-line
;; simple::kill-region
(defun kill-line-or-region () "Kill region if selected, otherwise kill line." (interactive)
(if (and mark-active transient-mark-mode)(kill-region (point)(mark))(kill-line)))
;; simple::transpose-lines
;; simple::kill-whole-line
(defun pull-line-down (N) "Pull line down N times." (interactive "*p")
(let ((col (current-column)))(kill-whole-line 1)(forward-line N)(yank 1)(pop kill-ring)(forward-line -1)
(move-to-column col)))
;; simple::transpose-lines
;; simple::kill-whole-line
(defun pull-line-up (N) "Pull line up N times." (interactive "*p")
(let ((col (current-column)))(kill-whole-line 1)(forward-line (- N))(yank 1)(pop kill-ring)(forward-line -1)
(move-to-column col)))
;; simple::goto-line
;; C::point
(defun pos-at-beginning-of-line (N) "Return the position at beginning of line N." (save-excursion (goto-line N)(point)))
(defun pos-at-end-of-line (N) "Return the position at end of line N." (save-excursion (goto-line N)(end-of-line)(point)))
;; simple::zap-to-char
;; C::delete-region
(defun zap-back-to-char (char) "Delete region back to, but not including, CHAR." (interactive "cZap back to char: ")
(let ((case-fold-search nil))
(delete-region (point)(progn (search-backward (char-to-string char))(forward-char)(point)))))
;; simple::zap-to-char
;; C::delete-region
(defun zap-up-to-char (char) "Delete region up to, but not including, CHAR." (interactive "cZap to char: ")
(let ((case-fold-search nil))
(delete-region (point)(progn (search-forward (char-to-string char))(backward-char)(point)))))
;; simple::delete-trailing-whitespace
;; whitespace::whitespace-buffer
(defun clean-trails () "Delete ^M glyphs, spaces, and tabs from line ends." (interactive) ; \r means ^M
(save-excursion (goto-char (point-min)) ; unlike delete-trailing-whitespace, clean-trails removes ^M (\r) in lisp-mode
(let ((count 0))(while (re-search-forward "[\r\t ]+$" nil t)(replace-match "")(setq count (+ count 1)))
(message "Cleaned %d lines" count))))
;; simple::delete-blank-lines
;; whitespace::whitespace-buffer
(defun delete-all-blank-lines () "Delete all blank lines in buffer." (interactive)
(save-excursion
(goto-char (point-min))
(let ((count 0))(while (search-forward "\n\n" nil t)(goto-char (point-min))
(while (search-forward "\n\n" nil t)(replace-match "\n")(setq count (+ count 1)))
(goto-char (point-min)))
(if (= (following-char) 10)(progn (delete-char 1)(setq count (+ count 1))))
(message "Deleted %d blank lines" count))))
;; simple::delete-indentation
(defun delete-indentation-nospace () "Join this line to previous with no whitespace at join." (interactive)
(delete-indentation)(delete-horizontal-space))
;; simple::end-of-buffer
;; simple::goto-line
(defun goto-longest-line () "Go to longest line in buffer." (interactive)
(let ((line 1)(length 0))
(save-excursion
(goto-char (point-min))(end-of-line)(setq length (current-column))
(while (not (eobp))
(progn (end-of-line 2)
(if (> (current-column) length)(progn (setq line (line-number-at-pos))(setq length (current-column)))))))
(goto-line line)(message "Line %d is %d characters" line length)))
;; C::downcase-region
;; C::downcase-word
;; belongs in simple
(defun downcase-word-or-region (N) "Downcase N words or region." (interactive "*p")
(if (and mark-active transient-mark-mode)(downcase-region (point)(mark))(downcase-word N)))
(defun upcase-word-or-region (N) "Upcase N words or region." (interactive "*p")
(if (and mark-active transient-mark-mode)(upcase-region (point)(mark))(upcase-word N)))
next reply other threads:[~2009-04-04 13:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-04 13:32 Arni Magnusson [this message]
2009-04-04 14:21 ` bug#2887: Suggestions for simple.el Stefan Monnier
2009-04-04 23:35 ` Arni Magnusson
2009-04-05 3:27 ` Stefan Monnier
2009-04-05 14:26 ` Leo
2009-04-05 20:17 ` Arni Magnusson
2009-04-05 21:59 ` Lennart Borgman
2009-04-06 2:14 ` Stefan Monnier
2009-04-06 3:02 ` Drew Adams
2009-04-07 2:46 ` Arni Magnusson
2009-04-07 14:02 ` Stefan Monnier
2009-04-07 16:09 ` Drew Adams
[not found] ` <008701c9b79b$41f3f250$0200a8c0@us.oracle.com>
2009-04-07 17:18 ` Stefan Monnier
2009-04-07 17:22 ` Chong Yidong
[not found] ` <87iqlg4bwl.fsf@cyd.mit.edu>
2009-04-07 17:26 ` Drew Adams
2009-04-07 21:43 ` Stefan Monnier
2009-04-18 0:08 ` Arni Magnusson
2009-04-18 19:32 ` Stefan Monnier
2009-04-19 1:13 ` Arni Magnusson
2009-04-19 1:40 ` Arni Magnusson
2009-04-19 3:14 ` Stefan Monnier
2009-04-19 13:41 ` Arni Magnusson
2020-09-19 21:50 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=26172.194.144.135.59.1238851923.squirrel@www.hafro.is \
--to=arnima@hafro.is \
--cc=2887@emacsbugs.donarmstrong.com \
--cc=bug-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).