0

I have free-form text logs with JSON-ish objects that I would like to selectively hide when analyzing the logs. They look something like this

2018-10-09 09:47:34.269 [T] T {

2018-10-09 09:47:34.269 [T] T   {

2018-10-09 09:47:34.269 [T] T      foo

2018-10-09 09:47:34.269 [T] T   }

2018-10-09 09:47:34.269 [T] T }

and I might want to collapse the inner pair and not show the line with foo on it, for example.

As far as I can figure out, hideshow.el does this, but I have not managed to enable it for text mode. I have the following in my .emacs

(defvar hs-special-modes-alist
      '((c-mode "{" "}" "/[*/]" nil nil)
        (text-mode "(" ")" "{" "}" "\[*\]" nil nil)))

which Emacs swallows, but if I try to enable hs-minor-mode while in text mode I still get Text Mode doesn’t support Hideshow Minor Mode. I cannot figure out what the nils are for here, or how many I should have (if any).

I don't necessarily have to use hideshow if that is the wrong package to use for this.

Solution

Solved by negas answer below. comment-start defines what a comment looks like, which I don't need, but it needs to be set for hideshow to be happy. I solved my problem by setting comment-start to something that won't likely occur in my logs:

(setq-local comment-start "///COMMENT")
Per Knytt
  • 103
  • 3
  • 1
    I'll remove the purecopy since it's useless (it's only meaningful for code executed while building the emacs executable). – Stefan Oct 11 '18 at 12:38

2 Answers2

1

In the text-mode buffer where your log is, set comment-start.

hideshow checks this and comment-end at the beginning of hs-grok-mode-type(). hs-grok-mode-type() says:

Set up hideshow variables for new buffers.
If `hs-special-modes-alist' has information associated with the
current buffer's major mode, use that.
Otherwise, guess start, end and `comment-start' regexps; `forward-sexp'
function; and adjust-block-beginning function.

text-mode doesn't set comment-start (it's nil), and without it, hideshow cant do it's "guessing".

nega
  • 3,221
  • 15
  • 21
-1

HideShow is meant to hide comment (or comment-like) text, which would involve having a language syntax. Text mode doesn't have such a syntax.

Felipe Lema
  • 757
  • 3
  • 11
  • I thought that the hs-special-modes-alist was there to define the syntax. I clarified that I don't have to use hideshow necessarily, it's just the package that seemed closest to what I want. – Per Knytt Oct 11 '18 at 12:28
  • Hideshow can hide comment text. From the first sentence of its manual "allows you to selectively display portions of a program, which are referred to as blocks". Comments are just blocks, as are C functions, and Lisp sexps. – nega Oct 12 '18 at 14:50