To create a list from sentences in org mode, I use following command
string-insert-rectangle
replace-regexp ^ with -
How can I combine these two to form a single keyboard short-cut?
As comments have mentioned, org-toggle-item
may suit your needs. Though this seems like a great opportunity to learn Emacs Lisp. The following code though does as explain:
(defun my-toggle-item (start end)
;; interactive r says that the parameters START and END
;; should be populated from the active region.
(interactive "r")
;; save which line the region starts and ends on
(let ((start-line (save-excursion
(goto-char start)
(line-number-at-pos)))
(end-line (save-excursion
(goto-char end)
(line-number-at-pos))))
;; open rectangle on region
(open-rectangle start end)
;; calculate new start and end points and run replace
(let ((region-start (save-excursion (goto-line start-line) (beginning-of-line) (point)))
(region-end (save-excursion (goto-line end-line) (end-of-line) (point))))
(replace-regexp-in-region "^" "- " region-start region-end))))
One edge case with this implementation is that it adds a dash even on blank lines.
The following is another way we could solve this:
(defun my-toggle-item (start end)
;; interactive r says that the parameters START and END
;; should be populated from the active region.
(interactive "r")
;; save which line the region starts and ends on
(let ((start-line (save-excursion
(goto-char start)
(line-number-at-pos)))
(end-line (save-excursion
(goto-char end)
(line-number-at-pos))))
;; open rectangle on region
(open-rectangle start end)
;; starting from the start line,
(goto-line start-line)
;; loop until we move past where the region ended
(while (and (<= (line-number-at-pos) end-line)
;; make sure we're also not at the end of buffer
(not (eobp)))
(when (not (looking-at "\n")) ; ignore lines without text
(skip-chars-forward " \t")
(insert "- "))
(forward-line))
;; move point to where the region began
(goto-line start-line)
(skip-chars-forward " \t")))
C- -
(control minus) on a region will turn lines into list items, by callingorg-toggle-item
ororg-cycle-list-bullet
accordingly.