unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11295: 24.0.95; New ibuffer filter derived-mode
@ 2012-04-21 11:11 Ivan Andrus
  2012-04-21 14:24 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Ivan Andrus @ 2012-04-21 11:11 UTC (permalink / raw)
  To: 11295

I have often wished to be able to use derived-mode instead of mode when
filtering in ibuffer.  This allows, for example, grouping all make files
without specifying each variant make file mode individually.  I finally
looked into adding this and it's very easy.

I have attached one possible implemention below.  I feel it's definitely
a trivial addition (I don't have papers on file with the FSF) since it
consists mostly of copy/paste from `derived-mode-p' and the `mode'
ibuffer-filter.  If, however, you disagree that it's not trivial, please
reimplement as needed.  You can also contact me about papers, though it
seems like a lot of work for such a small addition.


  (define-ibuffer-filter derived-mode
      "Toggle current view to buffers whose major mode inherits from QUALIFIER."
    (:description "major mode"
                  :reader
                  (intern
                   (completing-read "Filter by major mode: " obarray
                                    #'(lambda (e)
                                        (string-match "-mode$"
                                                      (symbol-name e)))
                                    t
                                    (let ((buf (ibuffer-current-buffer)))
                                      (if (and buf (buffer-live-p buf))
                                          (symbol-name (buffer-local-value 'major-mode buf))
                                        "")))))
    (let ((parent (buffer-local-value 'major-mode buf)))
      (while (and (not (eq parent qualifier))
                  (setq parent (get parent 'derived-mode-parent))))
      (eq parent qualifier)))


In GNU Emacs 24.0.95.1 (i386-apple-darwin10.8.0, NS apple-appkit-1038.36)
of 2012-04-07 on oroszlan.local





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

* bug#11295: 24.0.95; New ibuffer filter derived-mode
  2012-04-21 11:11 bug#11295: 24.0.95; New ibuffer filter derived-mode Ivan Andrus
@ 2012-04-21 14:24 ` Stefan Monnier
  2012-04-21 15:24   ` Ivan Andrus
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2012-04-21 14:24 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 11295

>   (define-ibuffer-filter derived-mode
>       "Toggle current view to buffers whose major mode inherits from QUALIFIER."
>     (:description "major mode"
>                   :reader
>                   (intern
>                    (completing-read "Filter by major mode: " obarray
>                                     #'(lambda (e)
>                                         (string-match "-mode$"
>                                                       (symbol-name e)))

This completion table doesn't sound very good.  Much better would be to
collect all major modes in use and all their parents.

>                                     t
>                                     (let ((buf (ibuffer-current-buffer)))
>                                       (if (and buf (buffer-live-p buf))
>                                           (symbol-name (buffer-local-value 'major-mode buf))
>                                         "")))))
>     (let ((parent (buffer-local-value 'major-mode buf)))
>       (while (and (not (eq parent qualifier))
>                   (setq parent (get parent 'derived-mode-parent))))
>       (eq parent qualifier)))

Why not use (with-current-buffer buf (derived-mode-p parent))?

Another question: couldn't it simply *replace* the existing mode filter?

I guess it could be a bit annoying if you want to see fundamental-mode
buffers (since most modes derive from it), but that's the only downside
I can think of.


        Stefan





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

* bug#11295: 24.0.95; New ibuffer filter derived-mode
  2012-04-21 14:24 ` Stefan Monnier
@ 2012-04-21 15:24   ` Ivan Andrus
  2012-04-21 19:44     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Ivan Andrus @ 2012-04-21 15:24 UTC (permalink / raw)
  To: 11295

On Apr 21, 2012, at 4:24 PM, Stefan Monnier wrote:

>> (define-ibuffer-filter derived-mode
>>     "Toggle current view to buffers whose major mode inherits from QUALIFIER."
>>   (:description "major mode"
>>                 :reader
>>                 (intern
>>                  (completing-read "Filter by major mode: " obarray
>>                                   #'(lambda (e)
>>                                       (string-match "-mode$"
>>                                                     (symbol-name e)))
> 
> This completion table doesn't sound very good.  Much better would be to
> collect all major modes in use and all their parents.

That is a much better idea.  As I said, I just copy/pasted without thinking too much.  My main use case is for `ibuffer-saved-filter-groups' so completion doesn't matter at all there.

>>                                   t
>>                                   (let ((buf (ibuffer-current-buffer)))
>>                                     (if (and buf (buffer-live-p buf))
>>                                         (symbol-name (buffer-local-value 'major-mode buf))
>>                                       "")))))
>>   (let ((parent (buffer-local-value 'major-mode buf)))
>>     (while (and (not (eq parent qualifier))
>>                 (setq parent (get parent 'derived-mode-parent))))
>>     (eq parent qualifier)))
> 
> Why not use (with-current-buffer buf (derived-mode-p parent))?

Uh.  That would have been too easy.  :-)

> Another question: couldn't it simply *replace* the existing mode filter?

> I guess it could be a bit annoying if you want to see fundamental-mode
> buffers (since most modes derive from it), but that's the only downside
> I can think of.


I thought about it, but I do in fact filter by fundamental-mode (and a few other modes) to hide "useless" buffers.  

-Ivan




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

* bug#11295: 24.0.95; New ibuffer filter derived-mode
  2012-04-21 15:24   ` Ivan Andrus
@ 2012-04-21 19:44     ` Stefan Monnier
  2012-04-23 18:51       ` Ivan Andrus
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2012-04-21 19:44 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 11295

>> Why not use (with-current-buffer buf (derived-mode-p parent))?
> Uh.  That would have been too easy.  :-)

I can relate to that.

>> Another question: couldn't it simply *replace* the existing mode filter?
>> I guess it could be a bit annoying if you want to see fundamental-mode
>> buffers (since most modes derive from it), but that's the only downside
>> I can think of.
> I thought about it, but I do in fact filter by fundamental-mode (and a few
> other modes) to hide "useless" buffers.  

Fair enough.  Please send us an updated patch, so we can install it,


        Stefan





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

* bug#11295: 24.0.95; New ibuffer filter derived-mode
  2012-04-21 19:44     ` Stefan Monnier
@ 2012-04-23 18:51       ` Ivan Andrus
  2012-04-24  3:46         ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Ivan Andrus @ 2012-04-23 18:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 11295

[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]

On Apr 21, 2012, at 9:44 PM, Stefan Monnier wrote:

>>> Why not use (with-current-buffer buf (derived-mode-p parent))?
>> Uh.  That would have been too easy.  :-)
> 
> I can relate to that.
> 
>>> Another question: couldn't it simply *replace* the existing mode filter?
>>> I guess it could be a bit annoying if you want to see fundamental-mode
>>> buffers (since most modes derive from it), but that's the only downside
>>> I can think of.
>> I thought about it, but I do in fact filter by fundamental-mode (and a few
>> other modes) to hide "useless" buffers.  
> 
> Fair enough.  Please send us an updated patch, so we can install it,


Attached is an updated patch.  I also added a keybinding, though I'm not entirely happy with it.  I chose / w since w is an upside down m.  My first choices of m, M, p, P, d, and D were all taken.  They were for mode, parent, and derived.  Feel free to ignore or change that portion.  Perhaps the key should replace one of the current mode filter keys m and M.

FWIW, I contacted assign@gnu.org for some changes in expand-region.el.

-Ivan


[-- Attachment #2: ibuffer.patch --]
[-- Type: application/octet-stream, Size: 2088 bytes --]

=== modified file 'lisp/ibuf-ext.el'
--- lisp/ibuf-ext.el	2012-01-19 07:21:25 +0000
+++ lisp/ibuf-ext.el	2012-04-23 17:58:13 +0000
@@ -973,8 +973,9 @@
        (concat " [" (cadr type) ": " (format "%s]" (cdr qualifier)))))))
 
 
-(defun ibuffer-list-buffer-modes ()
+(defun ibuffer-list-buffer-modes (&optional include-parents)
   "Create an alist of buffer modes currently in use.
+If INCLUDE-PARENTS is non-nil then include parent modes.
 The list returned will be of the form (\"MODE-NAME\" . MODE-SYMBOL)."
   (let ((bufs (buffer-list))
 	(modes)
@@ -982,10 +983,13 @@
     (while bufs
       (setq this-mode (buffer-local-value 'major-mode (car bufs))
 	    bufs (cdr bufs))
-      (add-to-list
-       'modes
-       `(,(symbol-name this-mode) .
-	 ,this-mode)))
+      (while this-mode
+	(add-to-list
+	 'modes
+	 `(,(symbol-name this-mode) .
+	   ,this-mode))
+	(setq this-mode (and include-parents
+			     (get this-mode 'derived-mode-parent)))))
     modes))
 
 
@@ -1027,6 +1031,16 @@
 				      "")))))
   (eq qualifier (buffer-local-value 'major-mode buf)))
 
+(define-ibuffer-filter derived-mode
+    "Toggle current view to buffers whose major mode inherits from QUALIFIER."
+  (:description "derived mode"
+		:reader
+		(intern
+		 (completing-read "Filter by derived mode: "
+				  (ibuffer-list-buffer-modes t)
+				  nil nil "")))
+  (with-current-buffer buf (derived-mode-p qualifier)))
+
 ;;;###autoload (autoload 'ibuffer-filter-by-name "ibuf-ext")
 (define-ibuffer-filter name
   "Toggle current view to buffers with name matching QUALIFIER."

=== modified file 'lisp/ibuffer.el'
--- lisp/ibuffer.el	2012-03-12 02:41:22 +0000
+++ lisp/ibuffer.el	2012-04-23 16:04:06 +0000
@@ -504,6 +504,7 @@
 
     (define-key map (kbd "/ m") 'ibuffer-filter-by-mode)
     (define-key map (kbd "/ M") 'ibuffer-filter-by-used-mode)
+    (define-key map (kbd "/ w") 'ibuffer-filter-by-derived-mode)
     (define-key map (kbd "/ n") 'ibuffer-filter-by-name)
     (define-key map (kbd "/ c") 'ibuffer-filter-by-content)
     (define-key map (kbd "/ e") 'ibuffer-filter-by-predicate)


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

* bug#11295: 24.0.95; New ibuffer filter derived-mode
  2012-04-23 18:51       ` Ivan Andrus
@ 2012-04-24  3:46         ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2012-04-24  3:46 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 11295

> Attached is an updated patch.

Thank you, installed.

> I also added a keybinding, though I'm not
> entirely happy with it.  I chose / w since w is an upside down m.  My first
> choices of m, M, p, P, d, and D were all taken.  They were for mode, parent,
> and derived.  Feel free to ignore or change that portion.  Perhaps the key
> should replace one of the current mode filter keys m and M.

`/ m' and `/ M' do the same, with `/ M' being the one with better
completion, so I moved the `/ M' binding to `/ m' and bound yours to `/ M'.

> FWIW, I contacted assign@gnu.org for some changes in expand-region.el.

Thank you very much,


        Stefan






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

end of thread, other threads:[~2012-04-24  3:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-21 11:11 bug#11295: 24.0.95; New ibuffer filter derived-mode Ivan Andrus
2012-04-21 14:24 ` Stefan Monnier
2012-04-21 15:24   ` Ivan Andrus
2012-04-21 19:44     ` Stefan Monnier
2012-04-23 18:51       ` Ivan Andrus
2012-04-24  3:46         ` Stefan Monnier

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