1 ;;; elbb-misc-utils.el --- misc-utils for all Emacsen
4 ;; This is free software: you can redistribute it and/or modify
5 ;; it under the terms of the GNU General Public License as published by
6 ;; the Free Software Foundation, either version 2 of the License, or
7 ;; (at your option) any later version.
9 ;; This is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
17 ;; Copyright (C) 2009 by Andreas Roehler
18 ;; Author Andreas Roehler <andreas.roehler@online.de>
20 (defun read-buffer-by-top-level-form (&optional beg end
)
21 "Read buffer step by step by top-level-form.
22 Prints position into the message-buffer after evaluation.
23 Stepps through region if activated, otherwise takes the whole buffer."
25 (when (string-match ".gnu-emacs-all-cvs" (buffer-file-name)) (emacs-lisp-mode))
26 (let ((beg (cond (beg beg
)
30 (end (cond (end (copy-marker end
))
32 (copy-marker (region-end)))
33 (t (copy-marker (point-max)))))
40 (while (and (not (eobp))
42 (setq last-pos-line
(count-lines 1 (point)))
43 (message "%s" last-pos-line
)
46 (while (nth 4 (parse-partial-sexp (line-beginning-position) (point)))
49 (message "point %s" (point))
50 (setq this-pos-line
(count-lines 1 (point)))
51 (if (eq 1 (- this-pos-line last-pos-line
))
52 (unless (y-or-n-p "Attention: Single line espressions. Continue?")
53 (throw 'fehler
(ignore)))
55 (eval-last-sexp nil
))))
56 (message "%s" " Finished! Buffer was set `read-only' for security reasons. ")))))
58 ;; (global-set-key [(control kp-9)] 'reverse-chars)
59 (defun reverse-chars ()
60 "Reverse reciproke chars as \"[\" to \"]\", upcase or downcase. "
62 (let* ((cf (char-after))
64 (cond ((or (eq cf
62)(eq cf ?\
>))
66 ((or (eq cf
60)(eq cf ?\
<))
68 ((or (eq cf
40)(eq cf ?\
())
70 ((or (eq cf
41)(eq cf ?\
)))
72 ((or (eq cf
123) (eq cf ?\
{))
74 ((or (eq cf
125) (eq cf ?\
}))
76 ((or (eq cf
93)(eq cf ?\
]))
78 ((or (eq cf
91)(eq cf ?\
[))
80 ((or (eq cf
45)(eq cf ?\-
))
82 ((or (eq cf
95)(eq cf ?\_
))
85 (setq cn
(upcase cf
)))))
89 (require 'thing-at-point-utils
)
90 ;; thing-at-point-utils are available at
91 ;; https://code.launchpad.net/s-x-emacs-werkstatt/
92 (defun peel-list-atpt ()
93 "Remove list at point, preserve inner lists.
94 Whatever is part of a list at the
95 beginning and end of the present i.e. sourrounding list
97 Must be called from the part of list to remove."
100 (let* ((bounds (bounds-of-list-atpt))
103 (when (eq beg
(point))
106 (let* ((bounds (bounds-of-list-atpt))
107 (inner-beg (car bounds
))
108 (inner-end (cdr bounds
)))
109 (delete-region inner-end end
)
111 (delete-region beg inner-beg
)))))
113 ;; re-implemented here to run without `thing-at-point-utils'
115 (defun peel-list-at-point ()
116 "Remove list at point, preserve inner lists.
117 Whatever is part of a list at the
118 beginning and end of the present i.e. sourrounding list
120 Must be called from the part of list to remove."
123 (let ((beg (save-excursion (progn (beginning-of-thing 'list
) (point))))
124 (end (save-excursion (progn (end-of-thing 'list
) (point)))))
125 (when (eq beg
(point))
128 (let ((inner-beg (save-excursion (progn (beginning-of-thing 'list
) (point))))
129 (inner-end (save-excursion (progn (end-of-thing 'list
) (point)))))
130 (delete-region inner-end end
)
132 (delete-region beg inner-beg
)))))
134 ;; elbb-misc-utils.el ends here