all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* customize hideshow.el?
@ 2017-08-13 16:46 Stephen Leake
  2017-08-13 16:58 ` Yuri Khan
  2017-08-13 17:15 ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Leake @ 2017-08-13 16:46 UTC (permalink / raw)
  To: emacs-devel

I'd like to customize hideshow.el to display the first and last line in
each hidden block.

This makes sense (at least to me) for languages like Ada. For example,
suppose I have an "if then else" statement nested in a block:

   declare
   begin
      if  then
      elsif  then
      else
      end if;
   exception
   end;

But I realize the declare block is only needed in the first branch of
the if, so I'd like to change this to:

   if  then
      declare
      begin
      exception
      end;
   elsif  then
   else
   end if;

If all the code fits in one window, this is not hard. But if the "if
then else" is long, I'd like to hide it, so I can easily delete the
"declare begin" and "exception end". But I'd like to be sure where the
beginning and end of the "if then else" is, so I don't accidently delete
part of it:

   declare
   begin
      if  then
      ...
      end if;
   exception
   end;

However, hideshow.el, without any customizations, does this:

   declare
   begin...exception
   end;

I've looked into the hooks in hide-show; I can set
hs-adjust-block-beginning to get this:

   declare
   begin
      if  then...exception
   end;

but there is no corresponding hs-adjust-block-end hook.

Before I start trying to add hs-adjust-block-end, I'm looking for
advice.

Is there any way to use the existing hooks to get what I want?

Are there other modes like hideshow.el that are closer to what I want?

Anyone else want what I want?

-- 
-- Stephe



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

* Re: customize hideshow.el?
  2017-08-13 16:46 customize hideshow.el? Stephen Leake
@ 2017-08-13 16:58 ` Yuri Khan
  2017-08-14  4:44   ` Clément Pit-Claudel
  2017-08-13 17:15 ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Yuri Khan @ 2017-08-13 16:58 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

On Sun, Aug 13, 2017 at 11:46 PM, Stephen Leake
<stephen_leake@stephe-leake.org> wrote:

> If all the code fits in one window, this is not hard. But if the "if
> then else" is long, I'd like to hide it, so I can easily delete the
> "declare begin" and "exception end".

The pain you are experiencing is an indicator of a problem.
Specifically, the code you are dealing with is too complex.

You can treat the symptom with a painkiller such as hideshow. But the
root cause is better treated by extracting a
function/procedure/subroutine.



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

* Re: customize hideshow.el?
  2017-08-13 16:46 customize hideshow.el? Stephen Leake
  2017-08-13 16:58 ` Yuri Khan
@ 2017-08-13 17:15 ` Eli Zaretskii
  2017-08-13 19:35   ` Stephen Leake
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2017-08-13 17:15 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

> From: Stephen Leake <stephen_leake@stephe-leake.org>
> Date: Sun, 13 Aug 2017 11:46:55 -0500
> 
> I'd like to customize hideshow.el to display the first and last line in
> each hidden block.

Did you try "C-x $" (with an appropriate numerical argument)?



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

* Re: customize hideshow.el?
  2017-08-13 17:15 ` Eli Zaretskii
@ 2017-08-13 19:35   ` Stephen Leake
  2017-08-27 12:07     ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2017-08-13 19:35 UTC (permalink / raw)
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Stephen Leake <stephen_leake@stephe-leake.org>
>> Date: Sun, 13 Aug 2017 11:46:55 -0500
>> 
>> I'd like to customize hideshow.el to display the first and last line in
>> each hidden block.
>
> Did you try "C-x $" (with an appropriate numerical argument)?

I was not aware of that. It affects the whole buffer, but that's not a
problem.

With some wrappers to implement "hide lines more indented than this one"
and "unhide all", that might do it.

Thanks,

-- 
-- Stephe



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

* Re: customize hideshow.el?
  2017-08-13 16:58 ` Yuri Khan
@ 2017-08-14  4:44   ` Clément Pit-Claudel
  0 siblings, 0 replies; 6+ messages in thread
From: Clément Pit-Claudel @ 2017-08-14  4:44 UTC (permalink / raw)
  To: emacs-devel

On 2017-08-13 18:58, Yuri Khan wrote:
> You can treat the symptom with a painkiller such as hideshow. But the
> root cause is better treated by extracting a
> function/procedure/subroutine.

The OP seems to be refactoring existing code, so I'm not sure what this comment is getting at :/

Sure, ideally all code would be clean and nice and there would be no need for tools that work around ugly code.  In practice, though, it's hard to get people to agree on exactly what clean and nice code is, and many of us end up reading a lot of code they didn't write, cannot change, and don't necessarily like.  In these cases, "treating the symptoms with hideshow" sounds like a very reasonable approach.

Clément.






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

* Re: customize hideshow.el?
  2017-08-13 19:35   ` Stephen Leake
@ 2017-08-27 12:07     ` Stephen Leake
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 2017-08-27 12:07 UTC (permalink / raw)
  To: emacs-devel

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

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Stephen Leake <stephen_leake@stephe-leake.org>
>>> Date: Sun, 13 Aug 2017 11:46:55 -0500
>>> 
>>> I'd like to customize hideshow.el to display the first and last line in
>>> each hidden block.
>>
>> Did you try "C-x $" (with an appropriate numerical argument)?
>
> I was not aware of that. It affects the whole buffer, but that's not a
> problem.
>
> With some wrappers to implement "hide lines more indented than this one"
> and "unhide all", that might do it.
>
> Thanks,

Just for the record, this works for me:

(defun sal-ada-hide-block ()
  "Hide contents of block whose structure is on current line."
  (save-excursion
    (back-to-indentation)
    (setq selective-display (1+ (current-column)))))

(defun sal-ada-toggle-hide-block ()
  (interactive)
  (if selective-display
      (setq selective-display nil)
    (sal-ada-hide-block))
  (force-window-update (selected-window)))

(define-key ada-mode-map "\C-ch" 'sal-ada-toggle-hide-block)


-- 
-- Stephe



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

end of thread, other threads:[~2017-08-27 12:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-13 16:46 customize hideshow.el? Stephen Leake
2017-08-13 16:58 ` Yuri Khan
2017-08-14  4:44   ` Clément Pit-Claudel
2017-08-13 17:15 ` Eli Zaretskii
2017-08-13 19:35   ` Stephen Leake
2017-08-27 12:07     ` Stephen Leake

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.