0

I am using org-journal-mode. When I apply org-journal-new-entry (M-j), in order to open today’s journal file and start a new entry. But when I keep press M-j it contininues to add new entries.

Is it possible to overwrite the last entry if it is empty? or delete all empty entries in the past in order to keep journal empty?

◉ Tuesday, 18 April 2023 ▾
○ 11:14 I have fixed some stuff in the org mode.
○ 11:14
○ 11:14
○ 11:14
○ 11:18
○ 11:18
○ 11:18
○ 11:18
○ 11:18
○ 11:18

Wanted output would be:

◉ Tuesday, 18 April 2023 ▾
○ 11:14 I have fixed some stuff in the org mode.
○ 11:18

1 Answer 1

1

C-h f org-journal-new-entry says:

org-journal-new-entry is an autoloaded interactive byte-compiled Lisp
function in ‘org-journal.el’.

(org-journal-new-entry PREFIX &optional TIME)

Open today’s journal file and start a new entry.

With a PREFIX arg, open the today’s file, create a heading if it
doesn’t exist yet, but do not create a new entry.
...

So C-u M-j should do what you want (it won't delete empty entries: it just won't create a new one, if there is one there already).

EDIT: This is inaccurate: C-u M-j certainly will not delete empty entries, but it won't create a new one at all - even if there is no entry already. You need to do M-j to create a new entry.


EDIT 2: The OP indicated in a comment that he would be happy with essentially reversing the above behavior, so that M-j would do what C-u M-j did before and vice versa (assuming both he and I understood each other correctly).

The implementation of that is quite simple: write the "inverted" function and then bind it to the key:

(defun my/org-journal-new-entry (prefix &optional time)
  (interactive "P")                   
  (org-journal-new-entry (not prefix) time))

(with-eval-after-load "org-journal"
  (define-key org-journal-mode-map (kbd "M-j") #'my/org-journal-new-entry))

All the new function does is invert the meaning of the prefix argument.

There is no attempt to use org-journal-prefix-key here (which the OP has customized to M-): we hardwire the binding to M-j. If you customize org-journal-prefix-key to something other than M-, this keybinding will not follow the new setting.

6
  • Can we force M-j to act as C-u M-j?
    – alper
    Apr 18, 2023 at 21:33
  • I don't think my answer does what you want: see the edit. I'll probably delete it.
    – NickD
    Apr 18, 2023 at 21:56
  • C-u M-j will work work me but if possible I want to achieve it using M-j
    – alper
    Apr 18, 2023 at 22:27
  • 1
    See if you like the solution in EDIT 2.
    – NickD
    Apr 19, 2023 at 0:11
  • You perfectly understood me correctly :-) Thank you for putting additional time for the edit-2.
    – alper
    Apr 20, 2023 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.