unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: carlmarcos--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: Emanuel Berg <incal@dataswamp.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Changing buffer mode
Date: Fri, 22 Jul 2022 05:22:40 +0200 (CEST)	[thread overview]
Message-ID: <N7YvQu5--3-2@tutanota.com> (raw)
In-Reply-To: <878romj8ti.fsf@dataswamp.org>


Jul 22, 2022, 00:21 by incal@dataswamp.org:

> carlmarcos--- via Users list for the GNU Emacs text editor wrote:
>
>>>>>> With the following function I can change the mode of
>>>>>> a buffer. I would like to change it to use
>>>>>> `completing-read` using a list composed of a selection
>>>>>> of mode names. How can I go about doing that?
>>>>>>
>>>>>
>>>>> Use it?
>>>>>
>>>>>  (completing-read "drop: " '(little boy fat man))
>>>>>
>>>>
>>>> Yes, but then how can I update the buffer with the
>>>> new mode?
>>>>
>>>
>>> The same way you always do it?
>>>
>>
>> I do not know the usual way.
>>
>
> (emacs-lisp-mode) from Lisp and M-x emacs-lisp-mode RET
> interactively ...
>
> Anyway some code for you ... try the examples, last.
>

Although it is good, my intention was to limit the modes to a select few, and for the mode names to be visible to the user through the minibuffer completing-read.  


> ;;; -*- lexical-binding: t -*-
> ;;
> ;; this file:
> ;;   https://dataswamp.org/~incal/emacs-init/set-mode.el
>
> (defun mode-p (fun)
>  (let*((sfx "-mode")
>  (len (length sfx) ))
>  (and (functionp fun)
>  (string= sfx (substring (symbol-name fun) (- len))) )))
>
> (defun set-mode (&optional fun)
>  (interactive
>  (list (completing-read
>  "mode: "
>  obarray
>  (lambda (e) (mode-p e))
>  t
>  nil
>  nil
>  (symbol-name #'normal-mode)
>  )) )
>  (if fun
>  (let ((f (if (stringp fun)
>  (intern fun)
>  fun) ))
>  (when (mode-p f)
>  (apply (list f)) ))
>  (normal-mode) ))
>
> ;; (set-mode #'kill-emacs)        ; safe as not a mode
> ;; (set-mode #'fundamental-mode)  ; function
> ;; (set-mode "emacs-lisp-mode")   ; function name
> ;; (set-mode)                     ; derive mode from extention/hashbang
> ;; M-x set-mode RET conf-mode RET ; interactive explicit
> ;; M-x set-mode RET RET           ; ditto implicit
>
> -- 
> underground experts united
> https://dataswamp.org/~incal
>




  reply	other threads:[~2022-07-22  3:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-20  3:55 Changing buffer mode carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-20 15:50 ` Emanuel Berg
2022-07-21 14:39   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-21 14:50     ` Emanuel Berg
2022-07-21 15:55       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-21 18:41         ` Eduardo Ochs
2022-07-21 19:02           ` tomas
2022-07-22  0:21         ` Emanuel Berg
2022-07-22  3:22           ` carlmarcos--- via Users list for the GNU Emacs text editor [this message]
2022-07-22  4:00           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-22  4:13             ` Emanuel Berg
2022-07-22 18:11               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-22 18:21                 ` Emanuel Berg
2022-07-22 18:36                   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-21 16:52   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=N7YvQu5--3-2@tutanota.com \
    --to=help-gnu-emacs@gnu.org \
    --cc=carlmarcos@tutanota.com \
    --cc=incal@dataswamp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).