all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#2887: Suggestions for simple.el
@ 2009-04-04 13:32 Arni Magnusson
  2009-04-04 14:21 ` Stefan Monnier
  2020-09-19 21:50 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 27+ messages in thread
From: Arni Magnusson @ 2009-04-04 13:32 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- 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)))

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-09-19 21:50 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-04 13:32 bug#2887: Suggestions for simple.el Arni Magnusson
2009-04-04 14:21 ` 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
2009-04-07 16:09               ` Drew Adams
2009-04-07 17:18                 ` Stefan Monnier
2009-04-07 17:18                 ` Stefan Monnier
2009-04-07 17:22                 ` Chong Yidong
2009-04-07 17:26                   ` Drew Adams
2009-04-07 17:26                   ` Drew Adams
2009-04-07 21:43                   ` Stefan Monnier
2009-04-07 17:22                 ` Chong Yidong
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

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.