Remove deadline shortcut? [duplicate] - emacs

This question already has answers here:
How can remove the <scheduled date> in the org agenda view quickly?
(2 answers)
Closed 4 years ago.
Is there an easy way (with a keyboard shortcut) to remove a deadline or a schedule without actually closing the task?

Shortcut: C-u C-c C-s.
Why this works
to find all methods with schedule, do C-h a, enter "schedule". There seems to be only
org-schedule is an interactive compiled Lisp function in
โ€˜../elpa/org-9.0.9/org.elโ€™.
(org-schedule ARG &optional TIME)
Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
With one universal prefix argument, remove any scheduling date from the item.
With two universal prefix arguments, prompt for a delay cookie.
With argument TIME, scheduled at the corresponding date. TIME can
either be an Org date like "2011-07-24" or a delta like "+2d".
so you need to call org-schedule "with one universal prefix argument". See https://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Command-Arguments.html. The universal prefix argument is just C-u. In code, this is handled at org.el in org--deadline-or-schedule:
(pcase arg
(`(4)
(when (and old-date log)
(org-add-log-setup (if deadline? 'deldeadline 'delschedule)
nil old-date log))
(org-remove-timestamp-with-keyword keyword)
(message (if deadline? "Item no longer has a deadline."
"Item is no longer scheduled.")))
PS: The Emacs-geeks live at https://emacs.stackexchange.com.

Related

Bulk reschedule org agenda items preserving date

I sometimes forget to do one or more of my daily habits that happen at the same time each day and need to bring them current so I can get orgzly notifications of them.
I am able to shift a single item in org agenda preserving the date with M-x org-agenda-date-later and it reschedules that to the current date with whatever time existed.
If I try to use it as a bulk action by marking an item and doing B f org-agenda-date-later I get:
Debugger entered--Lisp error: (wrong-number-of-arguments #f(compiled-function (arg &optional what) (interactive "p") #<bytecode 0x1ad5eed>) 0)
org-agenda-date-later()
org-agenda-bulk-action(nil)
funcall-interactively(org-agenda-bulk-action nil)
call-interactively(org-agenda-bulk-action nil nil)
command-execute(org-agenda-bulk-action)
This tells me that org-agenda-date-later wasn't written to be used as a bulk action. One solution for this could be writing a bulk action that calls org-agenda-date-later multiple times but I do not know how to do that.
I searched for other solutions and I found something recommended by the author of org mode from the org mode FAQ:
(defun org-agenda-reschedule-to-today ()
(interactive)
(flet ((org-read-date (&rest rest) (current-time)))
(call-interactively 'org-agenda-schedule)))
This works as a bulk action but it loses the time the item was scheduled. That means I would have to go through my habits and reschedule the time for each one after doing this which is inconvenient.
There is the org-agenda-bulk-custom-functions to which you can add a key-binding and an associated function. So, for example, adding a binding for D after calling org-agenda-bulk-action, you could use
(setq org-agenda-bulk-custom-functions
`((?D (lambda () (call-interactively 'org-agenda-date-later)))
,#org-agenda-bulk-custom-functions))
It will pass the prefix on, allowing C-u -1 B D to reshedule the tasks a day earlier at the same time, for example.

How to use elisp to let user pick a date from calendar?

Just learn to write an interactive function in elisp:
If called with prefix, open calendar and get the date which is picked by user.
I try to do something like this:
(calendar)
(org-get-date-from-calendar)
It return today straight away instead of let user to pick a date.
I tried
(org-read-date)
And that worked for me
As you've seen, the problem is that after invoking (calendar) your code simply continues and doesn't wait around for any interactions in the calendar window. You need to prevent the emacs command loop from continuing until the user has selected a date.
Setting up your own keys is one way to do this. For example, if you look at the org-read-date-minibuffer-local-map variable in the org-mode source code, you can see that org-mode essentially takes over keys in calendar mode to allow the user to navigate the calendar while org-mode waits for the result. Studying this keymap and the org-eval-in-calendar function might give you some ideas on how to achieve what you want.
Another way to wait for the result is via recursive-edit. The code below enters the calendar and, by calling (recursive-edit), waits for the user to exit the calendar via the q key, which normally invokes calendar-exit. The code temporarily applies advice to that function to have it set a local variable to the date selected in the calendar before calling calendar-exit (via the funcall) and then exiting the recursive edit:
(let* (date
(adv '(lambda (fn &rest args)
(setq date (calendar-cursor-to-date))
(funcall fn args)
(exit-recursive-edit))))
(advice-add 'calendar-exit :around adv)
(calendar)
(message "Select the desired date, then type `q' to exit.")
(recursive-edit)
(advice-remove 'calendar-exit adv)
date)
Using advice can be a brittle approach, though. It potentially changes function semantics in unexpected ways โ€” and see this page for other potential problems โ€” plus there are probably other issues lurking with this approach with respect to abnormal exits. You're better off using keymap approaches like those used in org-mode.

Change the format of a word in Emacs-AUCTeX without actually selecting it

One nice feature of modern word processors is that one can change the format (say, from roman to italic) of a word without actually selecting it; one just needs to place the text cursor within the word and tell the word processor (via a keyboard shortcut) to change its format. (Smart editing, I believe it is sometimes called.)
Is there a way of doing that in Emacs-AUCTeX? (The usual way to change the format---that is, insert a format command---is to select the word [mark its region] and then press the key combination for the command [e.g. C-c C-f C-i to insert \textit{}].)
The shortcut C-c C-f calls TeX-font. Then it emphasizes/italicizes/whatever,
based on the last key chord. So the solution is to advice this function:
(defvar TeX-font-current-word t)
(defadvice TeX-font (before TeX-font-word (replace what))
"If nothing is selected and `TeX-font-current-word' is not nil,
mark current word before calling `TeX-font'."
(when (and TeX-font-current-word
(not replace)
(not (region-active-p))
(not (looking-at "\\s-")))
(unless (looking-back "\\s-") (backward-word))
(mark-word)))
(ad-activate 'TeX-font)
Now, when no region is selected, TeX-font will work as if the current word
was selected. You can turn this behavior on/off by setting TeX-font-current-word to t/nil.
In case there is no solution right from the spot, Emacs offers two ways basically once the succession of commands/keys is known:
either store them into a keyboard-macro, which be might called with just one key - or put all the commands into a function, make it a command, assign a key.

How to exchange words in emacs(by replace them with each other one) [duplicate]

This question already has answers here:
How can I swap or replace multiple strings in code at the same time?
(5 answers)
Closed 8 years ago.
Say I have some text like:
First one is good, so I used first one.Second one is bad, so I drop it.
I want to switch the 'first' and 'second',and like replace-string,leave the capital to the same case as original word.
Is there any built-in functions to handle this situations?
Edit:
Let me explain the problem further.If I use usual replace-string twice,will some times cause unwanted results.In the example above, If using replace-string first RET second RET, then replace-string second RET first RET,it will out put: First one is good. so I used first one.First one is bad, so I drop it. It also a problem in some case like "clientFolder=>serverFolder and server=> client"
#huaiyuan answered the same question here:
How can I swap or replace multiple strings in code at the same time?
His code allows you to enter arbitrary list of pairs to do parallel replacement.
Incidently, if you want to read some cool lisp code, click on #huaiyuan and read his answers.
Here's a great trick courtesy of Mickey's Mastering Emacs blog (see http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/ under the heading "Swapping Elements")
C-M-% \(first\)\|second RET \,(if \1 "second" "first") RET
Edit: and here's an elisp version of that:
(defun my-swap-text (a b)
"Swap two pieces of text wherever they appear, using `query-replace-regexp'."
(interactive "sSwap: \nswith: ")
(let ((use-region (and transient-mark-mode mark-active)))
(query-replace-regexp
(rx (or (group (eval a)) (eval b)))
(quote (replace-eval-replacement replace-quote (if (match-string 1) b a)))
nil
(when use-region (region-beginning))
(when use-region (region-end)))))
did you google search this at all?
http://kb.iu.edu/data/abdp.html

Emacs minibuffer message when typing C-x

Well. When I type some first keys of the key series, emacs write those keys in minibuffer after some interval of time. Like that: Typing C-x 4 will make C-x 4- visible in minibuffer.
The question is: can this be modified? I was thinking about making something like combining part of key-help (generated by C-h when type some keys) with this string.
Can interval for waiting this message be shorten too?
Is it subroutine?
Edited, new question
There is a message when I quit emacs with C-x C-c and have modified buffers, that ask me if I want to save them. How can I know that this message is here? I tried to look in (minibuffer-prompt) (minibuffer-contents) (buffer-substring (point-min) (point-max)), selecting (select-window (minibuffer-window)). Nothing gives me results.
Yes, the user option echo-keystrokes controls how much time elapses before the prefix key is shown in the minibuffer. From (emacs) Echo Area Customization:
User Option: echo-keystrokes
This variable determines how much time should elapse before command
characters echo. Its value must be an integer or floating point
number, which specifies the number of seconds to wait before
echoing. If the user types a prefix key (such as `C-x') and then
delays this many seconds before continuing, the prefix key is
echoed in the echo area. (Once echoing begins in a key sequence,
all subsequent characters in the same key sequence are echoed
immediately.)
If the value is zero, then command input is not echoed.
You can control the timing of this help message by setting suggest-key-bindings to a larger/smaller number.
(setq suggest-key-bindings 5) ; wait 5 seconds
There is no easy way to customize the behavior, you'd have to edit the C code for execute-extended-command, or use a replacement for it which also provides the help. One possibility for a replacement is the anything-complete library which has a replacement for execute-extended-command (note: I haven't tried it). It builds on top of the package anything, which is a different experience than the standard Emacs.
I wrote working version of what I wanted to implement.
To use, (require 'keylist), copy one or two last lines to .emacs and uncomment them.
As you can see through this code, I used this
(not cursor-in-echo-area)
(not (minibufferp))
(not (= 13 (aref (this-command-keys-vector) 0)))
to find out, if my minibuffer, or echo area is in use.
The difference between them is that minibuffer is used to read, and echo area is used to message something.
When you type C-x C-c cursor is placed in echo area, and value of cursor-in-echo-area is changed.
The last string (= 13 (aref (this-command-keys-vector) 0)) is the most funny. It is used to catch things like query-replace. When making raplacements, (this-command-keys-vector) shows that RET is the first key pressed, then keys of your choise(y,n). As far as I don't have key-sequences starting with RET, i am okay with this.