help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Commands to insert a heading and a new page


From: Emanuel Berg
Subject: Re: Commands to insert a heading and a new page
Date: Thu, 28 Mar 2024 04:12:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]