&doc_request_notify);
key_add_prefix(doc_default_cmd, "doc:notify:", &doc_notify);
key_add_prefix(doc_default_cmd, "doc:set:", &doc_set);
+ key_add_prefix(doc_default_cmd, "doc:append:", &doc_append);
## The document link pane
return 1;
}
+DEF_CMD(doc_append)
+{
+ struct pane *p = ci->home;
+ const char *attr = ksuffix(ci, "doc:append:");
+ const char *val = ci->str;
+ const char *old;
+
+ if (!val || !val[0])
+ return Enoarg;
+ /* Append the string to the attr. It attr doesn't
+ * exists, string first char of val and use that.
+ */
+ old = attr_find(p->attrs, attr);
+ if (!old) {
+ attr_set_str(&p->attrs, attr, val+1);
+ } else {
+ const char *pos = strstr(old, val+1);
+ int len = strlen(val+1);
+ if (pos &&
+ (pos == old || pos[-1] == val[0]) &&
+ (pos[len] == 0 || pos[len] == val[0]))
+ ; /* val already present */
+ else
+ attr_set_str(&p->attrs, attr, strconcat(p, old, val));
+ }
+ return 1;
+}
+
DEF_CMD(doc_get_attr)
{
struct doc *d = ci->home->data;
&doc_request_notify);
key_add_prefix(doc_default_cmd, "doc:notify:", &doc_notify);
key_add_prefix(doc_default_cmd, "doc:set:", &doc_set);
+ key_add_prefix(doc_default_cmd, "doc:append:", &doc_append);
}
static void do_doc_assign(struct pane *p safe, struct pane *doc safe)
DEF_CMD(whitespace_activate)
{
struct pane *p;
- char *v, *vn = NULL;
p = call_ret(pane, "attach-whitespace", ci->focus);
if (!p)
return Efail;
- v = pane_attr_get(p, "view-default");
- asprintf(&vn, "%s%swhitespace", v?:"", v?",":"");
- if (vn) {
- call("doc:set:view-default", p, 0, NULL, vn);
- free(vn);
- }
+ call("doc:append:view-default", p, 0, NULL, ",whitespace");
return 1;
}
p = focus['filename']
if p and ("COMMIT_EDITMSG" in p or "/.stgit" in p):
- focus.call("doc:set:view-default", "textfill,whitespace,autospell")
+ focus.call("doc:append:view-default", ",textfill,whitespace,autospell")
focus.call("doc:set:fill-width", "72")
if "/git/lustre-release/" in p:
# looks like a lustre commit, need to limit line width
if p and p[-3:] == ".md":
# Until I have a real markdown module, I need this at least.
if os.getenv("EDLIB_TESTING"):
- focus.call("doc:set:view-default", "textfill,whitespace")
+ focus.call("doc:append:view-default", ",textfill,whitespace")
else:
- focus.call("doc:set:view-default", "textfill,whitespace,autospell")
+ focus.call("doc:append:view-default", ",textfill,whitespace,autospell")
focus["fill-width"] = "72"
focus["fill:start-re"] = ("^("
"[^a-zA-Z0-9\\n]*$|" # empty/puctuation line
def autospell_activate(key, focus, comm2, **a):
autospell_view(focus)
- v = focus['view-default']
- if v:
- v = v + ',autospell'
- else:
- v = 'autospell'
- focus.call("doc:set:view-default", v)
+ focus.call("doc:append:view-default", ",autospell")
return 1
p = DiffPane(focus)
if p:
p.call("view:changed")
- focus.call("doc:set:view-default", "diff")
+ focus.call("doc:append:view-default", ",diff")
return 1
editor.call("global-set-command", "attach-diff", diff_view_attach)
if p:
p.call("view:changed")
- v = focus['view-default']
- if v:
- v = v + ',merge'
- else:
- v = 'merge'
- focus.call("doc:set:view-default", v)
+ focus.call("doc:append:view-default", ",merge")
if mark:
p.call("K:A-m", focus, mark)
return 1
def enable_fill(self, key, focus, num, **a):
"handle:interactive-cmd-fill-mode"
- v = focus['view-default']
if not self.cols:
self.cols = 72
self.call("doc:set:fill-width", "72")
- if v and 'textfill'in v:
- return 1
- elif v:
- v = v + ',textfill'
- else:
- v = 'textfill'
- focus.call("doc:set:view-default", v)
+ focus.call("doc:append:view-default", ",textfill")
return 1
def handle_space(self, key, focus, mark, **a):
# enable fill-paragraph and auto-fill at col 72
FillMode(focus, 72)
- v = focus['view-default']
- if v:
- v = v + ',textfill'
- else:
- v = 'textfill'
- focus.call("doc:set:view-default", v)
+ focus.call("doc:append:view-default", ",textfill")
return 1
editor.call("global-set-command", "attach-textfill", fill_mode_attach)
if p:
p.call("view:changed")
- v = focus['view-default']
- if v:
- v = v + ',view-calc'
- else:
- v = 'view-calc'
- focus.call("doc:set:view-default", v)
+ focus.call("doc:append:view-default", ",view-calc")
return 1
def calc_appeared(key, focus, **a):