all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Commands to insert a heading and a new page
@ 2024-03-26  9:16 Heime
  2024-03-27 22:48 ` tpeplt
  0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-03-26  9:16 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


I would like to have two commands, one to insert a heading, the other to
insert a new page in a buffer.  So I can easily traverse the code in a buffer.





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

* Re: Commands to insert a heading and a new page
  2024-03-26  9:16 Commands to insert a heading and a new page Heime
@ 2024-03-27 22:48 ` tpeplt
  2024-03-28  3:12   ` Emanuel Berg
  2024-03-28  9:42   ` Heime
  0 siblings, 2 replies; 10+ messages in thread
From: tpeplt @ 2024-03-27 22:48 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

> I would like to have two commands, one to insert a heading, the other to
> insert a new page in a buffer.  So I can easily traverse the code in a buffer.

The Emacs function ‘insert’ inserts text into the current buffer:

(insert &rest ARGS)

Insert the arguments, either strings or characters, at point.

A simple function to insert a form-feed character:

(defun new-page ()
  "Insert a page separator into the current buffer."
  (interactive)
  (newline)
  (insert ?\f)                 ;Form feed is \f or Ctrl-l or ASCII 012
  (newline))

‘insert’ accepts either characters or strings, so it could be used to
define a command that inserts whatever text you want in a heading.

(newline)
(insert "Header line 1\n")
(insert "Line 2\n")
(insert (format "Parameter is %s.\n" parm))

--



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

* Re: Commands to insert a heading and a new page
  2024-03-27 22:48 ` tpeplt
@ 2024-03-28  3:12   ` Emanuel Berg
  2024-03-31 15:49     ` [External] : " Drew Adams
  2024-03-28  9:42   ` Heime
  1 sibling, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2024-03-28  3:12 UTC (permalink / raw)
  To: help-gnu-emacs

tpeplt wrote:

> A simple function to insert a form-feed character:
>
> (defun new-page ()
>   "Insert a page separator into the current buffer."
>   (interactive)
>   (newline)
>   (insert ?\f)                 ;Form feed is \f or Ctrl-l or ASCII 012
>   (newline))

It is not used so often, why and when do you use it?

> ‘insert’ accepts either characters or strings, so it could
> be used to define a command that inserts whatever text you
> want in a heading.
>
> (newline)
> (insert "Header line 1\n")
> (insert "Line 2\n")
> (insert (format "Parameter is %s.\n" parm))

Here is a bunch of Elisp that maybe amuses you:

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/string.el

(defun sign (label &optional no-insert)
  (interactive "sLabel: \nP")
  (let*((vertical   "|")
        (horizontal  ?-)
        (corner     "+")
        (mid (format "%s %s %s" vertical label vertical))
        (len (length mid))
        (top (format "%s%s%s" corner (make-string (- len 2) horizontal) corner))
        (sgn (format "%s\n%s\n%s\n" top mid top)) )
    (if no-insert
        sgn
      (insert sgn) )))

;; +---------------------+
;; | This is not a bluff |
;; +---------------------+

(defun hline (&optional char)
  (interactive "P")
  (let ((len (- (window-width) (or (current-column) 0) 1))
        (c   (or (and (listp char) (car char))
                 (and (numberp char) char)
                 ?-) ))
    (insert (make-string len c)) ))

(defalias 'hl #'hline)

(when nil
  (hline)----------------------------------------------------------------------
  (hline 42)*******************************************************************
  (hline ?+)+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  M-x hline RET----------------------------------------------------------------
  C-u C-u C-u M-x hline RET@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  C-u 59 M-x hline RET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)

(defun string-data-p (str)
  (and (stringp str)
       (not (string= str ""))
       str) )

(defun region-to-string ()
  (when (use-region-p)
    (let ((beg (region-beginning))
          (end (region-end) ))
      (let ((str (buffer-substring-no-properties beg end)))
        (replace-regexp-in-string "\n" " " str) ))))

(provide 'string)

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Commands to insert a heading and a new page
  2024-03-27 22:48 ` tpeplt
  2024-03-28  3:12   ` Emanuel Berg
@ 2024-03-28  9:42   ` Heime
  1 sibling, 0 replies; 10+ messages in thread
From: Heime @ 2024-03-28  9:42 UTC (permalink / raw)
  To: tpeplt; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Thursday, March 28th, 2024 at 10:48 AM, tpeplt <tpeplt@gmail.com> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> > I would like to have two commands, one to insert a heading, the other to
> > insert a new page in a buffer. So I can easily traverse the code in a buffer.
> 
> 
> The Emacs function ‘insert’ inserts text into the current buffer:
> 
> (insert &rest ARGS)
> 
> Insert the arguments, either strings or characters, at point.
> 
> A simple function to insert a form-feed character:
> 
> (defun new-page ()
> "Insert a page separator into the current buffer."
> (interactive)
> (newline)
> (insert ?\f) ;Form feed is \f or Ctrl-l or ASCII 012
> (newline))

That does the job.
 
> ‘insert’ accepts either characters or strings, so it could be used to
> define a command that inserts whatever text you want in a heading.
> 
> (newline)
> (insert "Header line 1\n")
> (insert "Line 2\n")
> (insert (format "Parameter is %s.\n" parm))
> 
> --



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

* RE: [External] : Re: Commands to insert a heading and a new page
  2024-03-28  3:12   ` Emanuel Berg
@ 2024-03-31 15:49     ` Drew Adams
  2024-03-31 18:40       ` tpeplt
  2024-04-01  1:20       ` Emanuel Berg
  0 siblings, 2 replies; 10+ messages in thread
From: Drew Adams @ 2024-03-31 15:49 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs@gnu.org

> > A simple function to insert a form-feed character:

And two newline chars.

> > (defun new-page ()
> >   "Insert a page separator into the current buffer."
> >   (interactive)
> >   (newline)
> >   (insert ?\f);Form feed is \f or Ctrl-l or ASCII
> 012
> >   (newline))

`C-q C-j C-l C-j` does the same thing.

Get to know `C-q'.
Get to know the ASCII control chars.

> It is not used so often, why and when do you use it?

Sure it is.  Separate text/code pieces,
visually and for navigation.

See (emacs) `Pages':

https://www.gnu.org/software/emacs/manual/html_node/emacs/Pages.html

And customize page separator:

https://www.emacswiki.org/emacs/PrettyControlL
 
> ;; +---------------------+
> ;; | This is not a bluff |
> ;; +---------------------+

See also library boxquote.el:

https://github.com/davep/boxquote.el

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

* Re: [External] : Re: Commands to insert a heading and a new page
  2024-03-31 15:49     ` [External] : " Drew Adams
@ 2024-03-31 18:40       ` tpeplt
  2024-03-31 20:32         ` Drew Adams
  2024-04-01  1:20       ` Emanuel Berg
  1 sibling, 1 reply; 10+ messages in thread
From: tpeplt @ 2024-03-31 18:40 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emanuel Berg, help-gnu-emacs@gnu.org

Drew Adams <drew.adams@oracle.com> writes:

>> > A simple function to insert a form-feed character:
>
> And two newline chars.
>

Thanks.  Yes, the ‘defun’ is intentionally more verbose than the keystroke
solution you provided because:

1. The writer asked for a function
2. A function can be called in a programmatic way
3. It documents the operations that are performed

>> > (defun new-page ()
>> >   "Insert a page separator into the current buffer."
>> >   (interactive)
>> >   (newline)
>> >   (insert ?\f);Form feed is \f or Ctrl-l or ASCII
>> 012
>> >   (newline))
>
> `C-q C-j C-l C-j` does the same thing.
>
> Get to know `C-q'.
> Get to know the ASCII control chars.
>

Yes.  Your instructions can be a little confusing to new users.  Taken
literally, they won’t work.  New users should read that the key
sequences are:

C-j
C-q C-l
C-j

>> It is not used so often, why and when do you use it?
>
> Sure it is.  Separate text/code pieces,
> visually and for navigation.
>
> See (emacs) `Pages':
>
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Pages.html
>
> And customize page separator:
>
> https://www.emacswiki.org/emacs/PrettyControlL

Thank you for writing the ‘pp-c-l’ library (pp-c-l.el).

1. Is this library provided as a package?  If so, can you provide the
name of the archive?  It is not available from either
https://elpa.gnu.org/packages/ or http://stable.melpa.org/packages/.

2. After downloading the file, I added "-*- lexical-binding: t; -*-" to
the first line and compiled the file using Emacs 29.3.  The compiler
reported the following:

In toplevel form:
pp-c-l.el:126:23: Warning: avoid `lsh'; use `ash' instead
pp-c-l.el:187:19: Warning: Unused lexical argument `symbol'
pp-c-l.el:252:57: Warning: reference to free variable ‘pretty-control-l-mode’
pp-c-l.el:251:11: Warning: assignment to free variable ‘pretty-control-l-mode’

In refresh-pretty-control-l:
pp-c-l.el:269:9: Warning: reference to free variable ‘pretty-control-l-mode’

In end of data:
pp-c-l.el:200:33: Warning: the function ‘pp^L-make-glyph-code’ is not known to
    be defined.
pp-c-l.el:187:34: Warning: the function ‘pretty-control-l-mode’ is not known
    to be defined.

>  
>> ;; +---------------------+
>> ;; | This is not a bluff |
>> ;; +---------------------+
>
> See also library boxquote.el:
>
> https://github.com/davep/boxquote.el

This library, ‘boxquote’ is available as package in the ‘melpa-stable’
archive, listed above, so it can be easily installed, updated, or
un-installed.

--



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

* RE: [External] : Re: Commands to insert a heading and a new page
  2024-03-31 18:40       ` tpeplt
@ 2024-03-31 20:32         ` Drew Adams
  2024-04-01  2:07           ` Emanuel Berg
  0 siblings, 1 reply; 10+ messages in thread
From: Drew Adams @ 2024-03-31 20:32 UTC (permalink / raw)
  To: tpeplt; +Cc: Emanuel Berg, help-gnu-emacs@gnu.org

> >> > (newline)
> >> > (insert ?\f
> >> > (newline))
> >
> > `C-q C-j C-l C-j` does the same thing.
> >
> > Get to know `C-q'.
> > Get to know the ASCII control chars.
> 
> Yes.  Your instructions can be a little confusing to new users.  Taken
> literally, they won’t work.  New users should read that the key
> sequences are:
> 
> C-j
> C-q C-l
> C-j

Actually, that's not right.  But neither
was what I wrote. ;-(  This is correct:

C-q C-j
C-q C-l
C-q C-j

C-j is often bound, even by default in
vanilla Emacs (`emacs -Q'), to commands
that do other things, besides insert a
newline char.

E.g.: In `emacs-lisp-mode' it's bound
to `electric-newline-and-maybe-indent'.
In *scratch* it's bound to
`eval-print-last-sexp'.

If you want to insert a newline char
then use `C-q C-l'.  Don't use C-l.

> Thank you for writing the ‘pp-c-l’ library (pp-c-l.el).

De rien.

> 1. Is this library provided as a package?  If so, can you provide the
> name of the archive?  It is not available from either...

It's a Lisp file, `pp-c-l.el'.  The doc page
I mentioned points to the file, but here's
the direct URL:

https://www.emacswiki.org/emacs/download/pp-c-l.el

Just (require 'pp-c-l), after putting the file in
your `load-path`.  Nothing else is needed.

> 2. I added "-*- lexical-binding: t; -*-" to
> the first line

No reason to do that, here.

> and compiled the file using Emacs 29.3.  The compiler
> reported the following:

You can ignore the byte-compiler warnings.
You see them because the library's compatible
with older Emacs versions.

> >> ;; +---------------------+
> >> ;; | This is not a bluff |
> >> ;; +---------------------+
> >
> > See also library boxquote.el:
> >
> > https://github.com/davep/boxquote.el
>
> This library, ‘boxquote’ is available as package in the ‘melpa-stable’
> archive, listed above, so it can be easily installed, updated, or
> un-installed.

It can also be easily...just by downloading it
(a single Lisp file) FROM the GIT repo whose
URL I gave TO a directory in your `load-path'.

Here's the direct URL to the file:

https://github.com/davep/boxquote.el/raw/main/boxquote.el

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

* Re: [External] : Re: Commands to insert a heading and a new page
  2024-03-31 15:49     ` [External] : " Drew Adams
  2024-03-31 18:40       ` tpeplt
@ 2024-04-01  1:20       ` Emanuel Berg
  1 sibling, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2024-04-01  1:20 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

>> It is not used so often, why and when do you use it?
>
> Sure it is. Separate text/code pieces, visually and
> for navigation.

Indeed, it is an aspect of the interface and user experience.
Such issues are up to the editor or IDE to solve IMO.

I did 'grep "^\\\f" **/*.el' and provided that command makes
sense we don't have '\f' for that use case in the Emacs
source, good.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: [External] : Re: Commands to insert a heading and a new page
  2024-03-31 20:32         ` Drew Adams
@ 2024-04-01  2:07           ` Emanuel Berg
  2024-04-01 16:53             ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2024-04-01  2:07 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams wrote:

> It's a Lisp file, `pp-c-l.el'. The doc page I mentioned
> points to the file, but here's the direct URL:
>
> https://www.emacswiki.org/emacs/download/pp-c-l.el
>
> Just (require 'pp-c-l), after putting the file in your
> `load-path`. Nothing else is needed.

Still, people are more comfortable using the package manager
which is also a good method to find stuff (searching the
buffer).

>> 2. I added "-*- lexical-binding: t; -*-" to
>> the first line
>
> No reason to do that, here.

That's right, since it was introduced in Emacs 24 and your
source is compatible all the way back to Emacs 20. So no,
I don't think that would be appreciated in GNU ELPA :) Is that
why you don't want to put it there?

> You can ignore the byte-compiler warnings. You see them
> because the library's compatible with older Emacs versions.

Indeed, a lot of modern stuff cannot be used if you want to be
compatible with software released in 1997 :)

etc/HISTORY:

  GNU Emacs 20.1 (1997-09-15) emacs-20.1

-- 
underground experts united
https://dataswamp.org/~incal




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

* RE: [External] : Re: Commands to insert a heading and a new page
  2024-04-01  2:07           ` Emanuel Berg
@ 2024-04-01 16:53             ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2024-04-01 16:53 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs@gnu.org

> Drew Adams wrote:
> 
> > It's a Lisp file, `pp-c-l.el'. The doc page I mentioned
> > points to the file, but here's the direct URL:
> > https://www.emacswiki.org/emacs/download/pp-c-l.el
> >
> > Just (require 'pp-c-l), after putting the file in your
> > `load-path`. Nothing else is needed.
> 
> Still, people are more comfortable using the package manager
> which is also a good method to find stuff (searching the
> buffer).

Some people are more comfortable never
going outdoors. ;-)

Elisp on Emacs Wiki is also mirrored
at https://github.com/emacsmirror.

E.g., pp-c-l.el is here:
https://github.com/emacsmirror/pp-c-l



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

end of thread, other threads:[~2024-04-01 16:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-26  9:16 Commands to insert a heading and a new page Heime
2024-03-27 22:48 ` tpeplt
2024-03-28  3:12   ` Emanuel Berg
2024-03-31 15:49     ` [External] : " Drew Adams
2024-03-31 18:40       ` tpeplt
2024-03-31 20:32         ` Drew Adams
2024-04-01  2:07           ` Emanuel Berg
2024-04-01 16:53             ` Drew Adams
2024-04-01  1:20       ` Emanuel Berg
2024-03-28  9:42   ` Heime

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.