next : um next calls (um--header) and only prints the filename for piping : no more auto open
This commit is contained in:
parent
b4b05e7994
commit
b81d6f906e
1 changed files with 21 additions and 9 deletions
30
next/next.go
30
next/next.go
|
|
@ -4,9 +4,11 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/brtholomy/um/go/cmd"
|
||||
"github.com/brtholomy/um/go/flags"
|
||||
|
|
@ -70,30 +72,38 @@ func next(last string, desc string) (string, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
// calls (um-next) inside a running emacs server. which has the advantage of fetching the loaded
|
||||
// calls (um--header) inside a running emacs server. which has the advantage of fetching the loaded
|
||||
// value of um-date-format, and respecting any other loaded configuration we might add.
|
||||
//
|
||||
// other options would be to forego respecting Elisp config values, or loading from a common config
|
||||
// file and forcing emacs to load from there - which would be very un-Emacs. But as the file loading
|
||||
// assumes a running server anyway, might as well get the current values.
|
||||
// file and forcing emacs to load from there - which would be very un-Emacs.
|
||||
//
|
||||
// this is the point at which this design becomes weird. But I don't want to let Elisp suck this CLI
|
||||
// into its nasty grip. Go is far superior in this application and there's no way I'm writing the
|
||||
// `um tag` logic in Elisp.
|
||||
//
|
||||
// So I've got Go and and an ancient beloved Lisp machine trying to live together.
|
||||
func emacsNext(f string, tags string) error {
|
||||
func emacsHeader(f string, tags string) error {
|
||||
quotedargs := fmt.Sprintf(`"%s"`, f)
|
||||
if tags != "" {
|
||||
quotedargs = fmt.Sprintf(`%s "%s"`, quotedargs, tags)
|
||||
}
|
||||
fn := fmt.Sprintf(`(um-next %s)`, quotedargs)
|
||||
fn := fmt.Sprintf(`(um--header %s)`, quotedargs)
|
||||
// NOTE: no longer get any string back from the lisp function:
|
||||
if err := exec.Command("emacsclient", "--eval", fn).Run(); err != nil {
|
||||
out, err := exec.Command("emacsclient", "--eval", fn).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("emacsclient: %w", err)
|
||||
}
|
||||
// NOTE: grabbing from stdout adds a newline:
|
||||
header := strings.TrimRight(string(out), "\n")
|
||||
// NOTE: Unquote will convert \\n to \n and remove \":
|
||||
header, err = strconv.Unquote(header)
|
||||
if err != nil {
|
||||
return fmt.Errorf("strconv.Unquote: %w", err)
|
||||
}
|
||||
if err := os.WriteFile(f, []byte(header), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
// NOTE: sends filename to stdout for piping
|
||||
fmt.Println(f)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +125,9 @@ func Next(args []string) {
|
|||
if err != nil {
|
||||
log.Fatalf("um %s: %v", CMD, err)
|
||||
}
|
||||
if err := emacsNext(filename, opts.Tags.Val); err != nil {
|
||||
if err := emacsHeader(filename, opts.Tags.Val); err != nil {
|
||||
log.Fatalf("um %s: %v", CMD, err)
|
||||
}
|
||||
// NOTE: sends filename to stdout for piping
|
||||
fmt.Println(filename)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue