From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Emanuel Berg via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help,gmane.emacs.devel Subject: insert-string-centered / column before $ appears? Date: Wed, 04 Mar 2020 00:21:16 +0100 Message-ID: <87eeu96n4j.fsf@ebih.ebihd> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="78701"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: emacs-devel@gnu.org To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:g+fd5sKeIBid8JqDbcj1YGXpJQc= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 04 00:21:51 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9GrH-000KMP-Ew for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 04 Mar 2020 00:21:51 +0100 Original-Received: from localhost ([::1]:55054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9GrG-0006Il-GE for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 03 Mar 2020 18:21:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60545) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9Gqr-0006DV-7J for help-gnu-emacs@gnu.org; Tue, 03 Mar 2020 18:21:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9Gqq-0004Ax-6t for help-gnu-emacs@gnu.org; Tue, 03 Mar 2020 18:21:25 -0500 Original-Received: from ciao.gmane.io ([159.69.161.202]:33548) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j9Gqq-000495-1A for help-gnu-emacs@gnu.org; Tue, 03 Mar 2020 18:21:24 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1j9Gqo-000JmX-MC for help-gnu-emacs@gnu.org; Wed, 04 Mar 2020 00:21:22 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Followup-To: gmane.emacs.help Mail-Copies-To: never X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 159.69.161.202 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:122527 gmane.emacs.devel:245202 Archived-At: (defun insert-string-centered (string &optional far-right) (interactive `(,(read-from-minibuffer "string: ") ,(string-to-number (read-from-minibuffer "far-right column [default 69]: ") ))) (let*((max (if (< 0 far-right) far-right 69)) (str-len (length string)) (padding (+ (/ (- max str-len) 2) (if (= 0 (mod str-len 2)) 1 0))) (padding-str (make-string padding ?\ ))) (insert padding-str string) )) One (?) issue: 69 which is hardcoded above is the column that appears right before the $ char appears in Emacs. I take it this is stored somewhere? Tested on this file: https://dataswamp.org/~incal/FILM Source: https://dataswamp.org/~incal/emacs-init/edit.el -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal