unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andreas Roehler <andreas.roehler@easy-emacs.de>
Subject: general-purpose.el - a general-forms-resource-utility
Date: Thu, 06 Jul 2006 12:11:01 +0200	[thread overview]
Message-ID: <44ACE1B5.10909@easy-emacs.de> (raw)


There are general usable functions scattered in the
source files, which are useful in a lot of
circumstances and could be callable in a given context.

Roman-to-latin- and Latin-to-roman-numbers for example.

Just today I saw

(defun region-around-match (&optional n)
  (set-mark (match-beginning n))
  (goto-char (match-end n)))

(defun region-to-string ()
  (buffer-substring (min (point) (mark)) (max (point) (mark))))

in mlsupport.el.

To have an (indexed) collection of all these goodies,
not only developers would gain an additional - sorted -
resource: This would also be useful for beginners to
learn Elisp - as function given there will be rather
basic ones, avoiding complexity. Also the Elisp-Manual
could refer to in order to give more examples, to
deepen understanding.

To show up such basic utilities one by one and in
relation might help finding errors and/or to optimize
usage.

Already started to collect some forms (example below)
but realize, this should not be done by hand.

Post this here, as there are probably more ideas to
consider before a major writing effort starts.

At the moment I see the following requirements at such
a general-resource-utility:

- take a given function or form where the point is in
  and prompt the user where to sort it (as groups in
  customize deliver a hierarchy and system)

- display a list of clickable functions or forms the
  way `apropos' does; i.e. M-x `general-resource-utility'
  RET `string-strip' should display several
  string-strip-utilities to examine, insert at point etc.

- allow users to edit the collection via
  copy-and-paste; provide some automated indexing
  afterward

- display related topics as customize does with
  parent groups

- collect resources from inside Emacs and third party
  stuff separately. (As a lot of users and me too use
  such stuff, it should not be impossible to collect
  and use it, provided it doesn't not disturb
  distribution. There might be - and should be probably
  - a warning at least once in that case.)

---

Thought to use/adapt cus-edit.el as a starting
point.

Please send your suggestions and/or objections.

__
Andreas Roehler

;;;

;; Please look with patience at this decent
   beginning :)

;;;_. * move related functions

(defun skip-blank-lines-backward ()
  " "
  (interactive)
  (while (looking-at "[ \t]*$")
      (forward-line -1))
  (forward-line 1))

(defun skip-blank-lines-forward ()
  " "
  (interactive)
  (while (looking-at "[ \t\n]")
    (forward-line 1))
  (forward-line -1))


;;;_. * string related functions
;;;_. ** strip-whitespace
;;;_. *** string-strip

(defun string-strip (str beforep afterp)
  "Strip STR of any leading (if BEFOREP) and/or trailing (if AFTERP) space.
"
  (string-match (concat "\\`" (if beforep "\\s-*")
            "\\(.*?\\)" (if afterp "\\s-*\n?")
            "\\'") str)
  (match-string 1 str))

;; Source: comment-string-strip, newcomment.el, GNU Emacs 22.0.50.1  ;;

;;;_. *** truncate-string-left

(defun concat-and-truncate-string-left (str prefix newlen)
  ;; leave space for ... on the left
  (let ((len (length str))
    (lenprefix (length prefix))
    substr)
    (if (<= len newlen)
    str
      (setq newlen (max 0 (- newlen lenprefix)))
      (setq substr (substring str (max 0 (- len 1 newlen))))
      (concat prefix substr))))

;; Example:
;; (concat-and-truncate-string-left "dasddddd" "+++" 4)
;; -> "+++dd"

;; following ediff-truncate-string-left from ediff-init.el

;;;_. *** nonempty-string-p

(defsubst nonempty-string-p (string)
  (and (stringp string) (not (string= string ""))))

;; Source: ediff-nonempty-string-p; ediff-init.el ---
;; Macros, variables, and defsubsts used by Ediff
;; Author: Michael Kifer <kifer@cs.sunysb.edu> ;;

;;;_. *** kill-trailing-spaces

;;;_. *** clean-out-spaces

(defun string-reverse (s)
  "Return the mirror image of string S, without any trailing space."
  (comment-string-strip (concat (nreverse (string-to-list s))) nil t))

;; Source: comment-string-reverse, newcomment.el, GNU Emacs 22.0.50.1 ;;

;;;_. ** numeral-string-conversions
;;;_. *** decimal-to-roman

(defvar w3-roman-characters "ivxLCDMVX" "Roman numerals.")

(defun w3-decimal-to-roman (n)
  "Convert from decimal to roman numerals"

  (let ((curmod 1000)
    (str "")
    (j 7)
    i2 k curcnt)
    (while (>= curmod 1)
      (if (>= n curmod)
      (progn
        (setq curcnt (/ n curmod)
          n (- n (* curcnt curmod)))
        (if (= 4 (% curcnt 5))
        (setq i2 (+ j (if (> curcnt 5) 1 0))
              str (format "%s%c%c" str
                  (aref w3-roman-characters (1- j))
                  (aref w3-roman-characters i2)))
          (progn
        (if (>= curcnt 5)
            (setq str (format "%s%c" str (aref w3-roman-characters j))
              curcnt (- curcnt 5)))
        (setq k 0)
        (while (< k curcnt)
          (setq str (format "%s%c" str
                    (aref w3-roman-characters (1- j)))
            k (1+ k)))))))
      (setq curmod (/ curmod 10)
        j (- j 2)))
    str))

;; Source: w3-display.el --- W3 display engine.   Author: William M. 
Perry <wmperry@cs.indiana.edu" ;;

;;;_. *** decimal-to-alpha

(defun w3-decimal-to-alpha (n)
  "Convert from decimal to alphabetical (a, b, c, ..., aa, ab,...)"
  (cond
   ((< n 1) (char-to-string ?Z))
   ((<= n 26) (char-to-string (+ ?A (1- n))))
   (t (concat (w3-decimal-to-alpha (/ n 26))
          (w3-decimal-to-alpha (% n 26))))))

;;   Source: w3-display.el --- W3 display engine.   Author: William M. 
Perry <wmperry@cs.indiana.edu" ;;

;;;_. * clipboard related functions
;;;_. ** clipboard and x-select-enable-clipboard

(defun clipboard-yank ()
  "Insert the clipboard contents, or the last stretch of killed text."
  (interactive)
  (let ((x-select-enable-clipboard t))
    (yank)))

(defun clipboard-kill-ring-save (beg end)
  "Copy region to kill ring, and save in the X clipboard."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-ring-save beg end)))

(defun clipboard-kill-region (beg end)
  "Kill the region, and save it in the X clipboard."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-region beg end)))

;; Source: menu-bar.el ;;

;;;;; End

             reply	other threads:[~2006-07-06 10:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-06 10:11 Andreas Roehler [this message]
2006-07-06 19:57 ` general-purpose.el - a general-forms-resource-utility Eli Zaretskii
2006-07-06 20:34   ` Lennart Borgman
2006-07-07  6:13   ` Andreas Roehler
2006-07-07  4:14 ` Richard Stallman
2006-07-07  6:32   ` Andreas Roehler
2006-07-07  7:55     ` Thien-Thi Nguyen
2006-07-07  8:50       ` Andreas Roehler
2006-07-07 16:04         ` Thien-Thi Nguyen
2006-07-08  1:12     ` Richard Stallman
2006-07-07  4:15 ` Richard Stallman
2006-07-07  7:08   ` Andreas Roehler

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=44ACE1B5.10909@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    /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).