* Preventing inadvertent global modifications
@ 2023-09-12 16:47 Max Nikulin
2023-09-13 8:02 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Max Nikulin @ 2023-09-12 16:47 UTC (permalink / raw)
To: emacs-orgmode
Hi,
Yesterday, when I was going to commit changes after editing several
headings in different places of an Org file, I was surprised by huge
diff with hundreds of chunks. Tags spread across the whole file were
adjusted by one or tow spaces. Probably I just accidentally hit C-u
before setting a tag to a new heading by C-c C-q. Of course, I did not
noticed it immediately. I managed to create a commit with real changes
without noise due to tags realignment. However I would like to prevent
similar issues in future.
I can add a prompt for a particular argument of a function by
(defun nm-safe-org-set-tags-command (&optional arg)
"Call `org-set-tags-command' requiring to confirm
realigning of all tags."
(interactive "P")
(cond
((and (equal '(4) arg) (not (yes-or-no-p "Realign all tags? "))))
(t (call-interactively #'org-set-tags-command))))
(add-hook 'org-mode-hook
(lambda ()
(define-key org-mode-map (kbd "C-c C-q")
#'nm-safe-org-set-tags-command)))
The function can be made a bit smarter by adding minimal file size
threshold.
However almost certainly there are more function "destructive" in a
similar way. Is there a more general approach to make commands safer in
respect to global modifications?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing inadvertent global modifications
2023-09-12 16:47 Preventing inadvertent global modifications Max Nikulin
@ 2023-09-13 8:02 ` Ihor Radchenko
2023-09-13 10:50 ` Max Nikulin
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-09-13 8:02 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
Max Nikulin <manikulin@gmail.com> writes:
> Yesterday, when I was going to commit changes after editing several
> headings in different places of an Org file, I was surprised by huge
> diff with hundreds of chunks. Tags spread across the whole file were
> adjusted by one or tow spaces. Probably I just accidentally hit C-u
> before setting a tag to a new heading by C-c C-q. Of course, I did not
> noticed it immediately. I managed to create a commit with real changes
> without noise due to tags realignment. However I would like to prevent
> similar issues in future.
You can set `org-auto-align-tags' to nil.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing inadvertent global modifications
2023-09-13 8:02 ` Ihor Radchenko
@ 2023-09-13 10:50 ` Max Nikulin
2023-09-14 12:56 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Max Nikulin @ 2023-09-13 10:50 UTC (permalink / raw)
To: emacs-orgmode
On 13/09/2023 15:02, Ihor Radchenko wrote:
> Max Nikulin writes:
>
>> Yesterday, when I was going to commit changes after editing several
>> headings in different places of an Org file, I was surprised by huge
>> diff with hundreds of chunks. Tags spread across the whole file were
>> adjusted by one or tow spaces. Probably I just accidentally hit C-u
>> before setting a tag to a new heading by C-c C-q. Of course, I did not
>> noticed it immediately. I managed to create a commit with real changes
>> without noise due to tags realignment. However I would like to prevent
>> similar issues in future.
>
> You can set `org-auto-align-tags' to nil.
I saw it, but from its description I decided that its effect may be to
broad. I have tried it and to my surprise it does not affect editing of
heading, tags are kept aligned. M-<right> and M-<left> do not realign
tags, so the value is not ignored.
C-u C-c C-q still realigns all tags in the buffer, so this option would
not save me from getting huge diff.
I suspect there are enough commands having similar global (and so mostly
hidden) effect. I may be unaware of them because I do not feel that I
need such commands.
I admit that some fraction of users keep their files tidy calling C-u
C-c C-q regularly. Perhaps at certain moment I will decide no align
tags, but it should be a dedicated commit not mixed with other changes.
My opinion that, by default, commands performing massive changes should
require reasonable efforts to execute. It should help to avoid calling
them unintentionally. Perhaps there is a better approach than annoying
`yes-or-no-p'.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing inadvertent global modifications
2023-09-13 10:50 ` Max Nikulin
@ 2023-09-14 12:56 ` Ihor Radchenko
2023-09-15 11:00 ` Max Nikulin
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-09-14 12:56 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
Max Nikulin <manikulin@gmail.com> writes:
>> You can set `org-auto-align-tags' to nil.
>
> I saw it, but from its description I decided that its effect may be to
> broad. I have tried it and to my surprise it does not affect editing of
> heading, tags are kept aligned. M-<right> and M-<left> do not realign
> tags, so the value is not ignored.
We might indeed want to respect org-auto-align-tags everywhere.
> C-u C-c C-q still realigns all tags in the buffer, so this option would
> not save me from getting huge diff.
C-u C-c C-q is explicitly documented to do so. Surely, you may press
universal argument by accident, but so you do for, say, C-u C-u C-k,
deleting 16 lines at once. I am not sure if makes much sense to
intervene here.
> I suspect there are enough commands having similar global (and so mostly
> hidden) effect. I may be unaware of them because I do not feel that I
> need such commands.
No other commands call (org-align-tags t).
> I admit that some fraction of users keep their files tidy calling C-u
> C-c C-q regularly. Perhaps at certain moment I will decide no align
> tags, but it should be a dedicated commit not mixed with other changes.
> My opinion that, by default, commands performing massive changes should
> require reasonable efforts to execute. It should help to avoid calling
> them unintentionally. Perhaps there is a better approach than annoying
> `yes-or-no-p'.
I am reluctant (see the above), unless other users also think that such
feature would be useful.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing inadvertent global modifications
2023-09-14 12:56 ` Ihor Radchenko
@ 2023-09-15 11:00 ` Max Nikulin
0 siblings, 0 replies; 5+ messages in thread
From: Max Nikulin @ 2023-09-15 11:00 UTC (permalink / raw)
To: emacs-orgmode
On 14/09/2023 19:56, Ihor Radchenko wrote:
> Max Nikulin writes:
>
>> C-u C-c C-q still realigns all tags in the buffer, so this option would
>> not save me from getting huge diff.
>
> C-u C-c C-q is explicitly documented to do so. Surely, you may press
> universal argument by accident, but so you do for, say, C-u C-u C-k,
> deleting 16 lines at once. I am not sure if makes much sense to
> intervene here.
I have never tried to dispute that it is documented.
The issue is not prefix argument and not namely aligning tags, but a lot
of modifications scattered across file being invisible in the active frame.
I do not remember if I had problems due to C-k, but adding some friction
to C-w and M-w if the mark is too far away is in my plan. Fortunately I
usually can notice that C-w deletes significant part of my file because
mark was set in other window. So undo helps (attention is required
however to not revert undo to redo and to stop at proper point). Since
adjacent region may be unfolded in response to editing action, sometimes
it is hard to figure out if effect of key hit is consistent with
expectations.
> I am reluctant (see the above), unless other users also think that such
> feature would be useful.
Since nobody joined to the thread, I assume it is my personal pain,
perhaps related to Vim, perhaps to other experience. I can not say that
I am investing noticeable amount of efforts to eliminate it, but I hope
I will get better ideas in future.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-15 11:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-12 16:47 Preventing inadvertent global modifications Max Nikulin
2023-09-13 8:02 ` Ihor Radchenko
2023-09-13 10:50 ` Max Nikulin
2023-09-14 12:56 ` Ihor Radchenko
2023-09-15 11:00 ` Max Nikulin
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.