unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Reading major-mode name via completion?
@ 2016-05-29  2:54 raman
  2016-05-29 15:40 ` Stefan Monnier
  2016-05-29 18:47 ` Stephen Leake
  0 siblings, 2 replies; 5+ messages in thread
From: raman @ 2016-05-29  2:54 UTC (permalink / raw)
  To: emacs-devel

Is there a completion table that already exists in emacs that one
could pass to completing-read for reading in a major-mode name?

--raman 
-- 

-- 



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

* Re: Reading major-mode name via completion?
  2016-05-29  2:54 Reading major-mode name via completion? raman
@ 2016-05-29 15:40 ` Stefan Monnier
  2016-05-29 18:51   ` Stephen Leake
  2016-05-29 18:47 ` Stephen Leake
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2016-05-29 15:40 UTC (permalink / raw)
  To: emacs-devel

> Is there a completion table that already exists in emacs that one
> could pass to completing-read for reading in a major-mode name?

You might like to look at `customize-mode' which seems to provide
that completion.


        Stefan




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

* Re: Reading major-mode name via completion?
  2016-05-29  2:54 Reading major-mode name via completion? raman
  2016-05-29 15:40 ` Stefan Monnier
@ 2016-05-29 18:47 ` Stephen Leake
  2016-05-29 22:18   ` raman
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2016-05-29 18:47 UTC (permalink / raw)
  To: raman; +Cc: emacs-devel

raman@google.com writes:

> Is there a completion table that already exists in emacs that one
> could pass to completing-read for reading in a major-mode name?

I use this:

   (completing-read
    "mode: "
    (apply-partially
     #'completion-table-with-predicate
     obarray
     (lambda (sym) ;; predicate
       (or (get sym 'derived-mode-parent) ;; most modes
	   (get sym 'custom-mode-group) ;; ada-mode
	   ;; FIXME: leaves out fundamental-mode, maybe others
	   ))
     'strict)
    nil ;; predicate
    t ;; require-match
    (symbol-name major-mode) ;; initial
    history)

as the FIXME: says, it leaves out some.

-- 
-- Stephe



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

* Re: Reading major-mode name via completion?
  2016-05-29 15:40 ` Stefan Monnier
@ 2016-05-29 18:51   ` Stephen Leake
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2016-05-29 18:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Is there a completion table that already exists in emacs that one
>> could pass to completing-read for reading in a major-mode name?
>
> You might like to look at `customize-mode' which seems to provide
> that completion.

That essentially does:

(completing-read "prompt" obarray 'custom-group-of-mode ...)

`custom-group-of-mode' is used as the predicate in the completion; it
returns non-nil if the symbol has a custom group.

So this assumes all major modes have custom groups, which is only
approximately true.


-- 
-- Stephe



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

* Re: Reading major-mode name via completion?
  2016-05-29 18:47 ` Stephen Leake
@ 2016-05-29 22:18   ` raman
  0 siblings, 0 replies; 5+ messages in thread
From: raman @ 2016-05-29 22:18 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

Stephen Leake <stephen_leake@stephe-leake.org> writes:

Thanks! I cloned a small function out of customize-mode -- will attach
it.

I suspect my  code lets through  more cases,  
and  that your  predicate may also be tighter.
(defsubst soundscape-read-major-mode-name ()
  "Helper to read major-mode name with completion."
  (let ((completion-regexp-list '("-mode\\'")))
	(intern
	 (completing-read "Major mode: "
			  obarray
			  nil t nil nil nil))))

> raman@google.com writes:
>
>> Is there a completion table that already exists in emacs that one
>> could pass to completing-read for reading in a major-mode name?
>
> I use this:
>
>    (completing-read
>     "mode: "
>     (apply-partially
>      #'completion-table-with-predicate
>      obarray
>      (lambda (sym) ;; predicate
>        (or (get sym 'derived-mode-parent) ;; most modes
> 	   (get sym 'custom-mode-group) ;; ada-mode
> 	   ;; FIXME: leaves out fundamental-mode, maybe others
> 	   ))
>      'strict)
>     nil ;; predicate
>     t ;; require-match
>     (symbol-name major-mode) ;; initial
>     history)
>
> as the FIXME: says, it leaves out some.

-- 



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

end of thread, other threads:[~2016-05-29 22:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-29  2:54 Reading major-mode name via completion? raman
2016-05-29 15:40 ` Stefan Monnier
2016-05-29 18:51   ` Stephen Leake
2016-05-29 18:47 ` Stephen Leake
2016-05-29 22:18   ` raman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).