1 ;;; region-or.el --- functions dealing with region
5 ;; This file is free software; you can redistribute it
6 ;; and/or modify it under the terms of the GNU General
7 ;; Public License as published by the Free Software
8 ;; Foundation; either version 2, or (at your option)
11 ;; This file is distributed in the hope that it will be
12 ;; useful, but WITHOUT ANY WARRANTY; without even the
13 ;; implied warranty of MERCHANTABILITY or FITNESS FOR A
14 ;; PARTICULAR PURPOSE. See the GNU General Public
15 ;; License for more details.
17 ;; You should have received a copy of the GNU General
18 ;; Public License along with GNU Emacs; see the file
19 ;; COPYING. If not, write to the Free Software
20 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
25 ;; Purpose of this file is to collect as to discuss some
26 ;; small and general forms
28 ;; Everyone interested in Emacs Lisp should easily be
29 ;; able to augment or change this git-archive
31 ;; Instead of marking a region, quite often a default
32 ;; value may do the right thing - thus saving keystrokes.
34 ;; Below an example function: Maybe better methods
35 ;; exist? Comments welcome!
37 ;; Author: Andreas Roehler <andreas.roehler@online.de>
39 (defun return-region-or-line (&optional arg beg end
)
42 (let* ((beg (cond (beg beg
)
45 (t (line-beginning-position))))
46 (end (cond (end (copy-marker end
))
48 (copy-marker (region-end)))
49 (t (copy-marker (line-end-position)))))
50 (text (buffer-substring-no-properties beg end
)))
51 (when arg
(message "%s" text
))
56 ;; for (symbol-end-position-atpt) and
57 ;; (symbol-beginning-position-atpt) you need
58 ;; thingatpt-utils from
59 ;; https://code.launchpad.net/s-x-emacs-werkstatt/
61 ;; or replace this form with another one returning
64 (defun return-region-or-symbol (&optional arg beg end
)
67 (let* ((beg (cond (beg beg
)
70 (t (symbol-beginning-position-atpt))))
71 (end (cond (end (copy-marker end
))
73 (copy-marker (region-end)))
74 (t (copy-marker (symbol-end-position-atpt)))))
75 (text (buffer-substring-no-properties beg end
)))
76 (when arg
(message "%s" text
))