@@ -535,28 +535,24 @@ pub(super) fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()>
535
535
Ok ( ( ) )
536
536
}
537
537
538
- fn write_all_impl (
538
+ pub fn write_all_impl (
539
539
cx : & mut compositor:: Context ,
540
- _args : & [ Cow < str > ] ,
541
- event : PromptEvent ,
542
- quit : bool ,
543
540
force : bool ,
541
+ write_scratch : bool ,
544
542
) -> anyhow:: Result < ( ) > {
545
- if event != PromptEvent :: Validate {
546
- return Ok ( ( ) ) ;
547
- }
548
-
549
543
let mut errors = String :: new ( ) ;
550
544
let auto_format = cx. editor . config ( ) . auto_format ;
551
545
let jobs = & mut cx. jobs ;
552
546
// save all documents
553
547
for doc in & mut cx. editor . documents . values_mut ( ) {
554
- if doc. path ( ) . is_none ( ) {
555
- errors. push_str ( "cannot write a buffer without a filename\n " ) ;
548
+ if !doc. is_modified ( ) {
556
549
continue ;
557
550
}
558
551
559
- if !doc. is_modified ( ) {
552
+ if doc. path ( ) . is_none ( ) {
553
+ if write_scratch {
554
+ errors. push_str ( "cannot write a buffer without a filename\n " ) ;
555
+ }
560
556
continue ;
561
557
}
562
558
@@ -579,55 +575,46 @@ fn write_all_impl(
579
575
jobs. add ( Job :: new ( future) . wait_before_exiting ( ) ) ;
580
576
}
581
577
582
- if quit {
583
- if !force {
584
- buffers_remaining_impl ( cx. editor ) ?;
585
- }
586
-
587
- // close all views
588
- let views: Vec < _ > = cx. editor . tree . views ( ) . map ( |( view, _) | view. id ) . collect ( ) ;
589
- for view_id in views {
590
- cx. editor . close ( view_id) ;
591
- }
578
+ match errors. len ( ) {
579
+ 0 => Ok ( ( ) ) ,
580
+ _ => bail ! ( errors) ,
592
581
}
593
-
594
- bail ! ( errors)
595
582
}
596
583
597
- pub fn write_all (
584
+ fn write_all (
598
585
cx : & mut compositor:: Context ,
599
- args : & [ Cow < str > ] ,
586
+ _args : & [ Cow < str > ] ,
600
587
event : PromptEvent ,
601
588
) -> anyhow:: Result < ( ) > {
602
589
if event != PromptEvent :: Validate {
603
590
return Ok ( ( ) ) ;
604
591
}
605
592
606
- write_all_impl ( cx, args , event , false , false )
593
+ write_all_impl ( cx, false , true )
607
594
}
608
595
609
596
fn write_all_quit (
610
597
cx : & mut compositor:: Context ,
611
- args : & [ Cow < str > ] ,
598
+ _args : & [ Cow < str > ] ,
612
599
event : PromptEvent ,
613
600
) -> anyhow:: Result < ( ) > {
614
601
if event != PromptEvent :: Validate {
615
602
return Ok ( ( ) ) ;
616
603
}
617
-
618
- write_all_impl ( cx, args , event , true , false )
604
+ write_all_impl ( cx , false , true ) ? ;
605
+ quit_all_impl ( cx. editor , false )
619
606
}
620
607
621
608
fn force_write_all_quit (
622
609
cx : & mut compositor:: Context ,
623
- args : & [ Cow < str > ] ,
610
+ _args : & [ Cow < str > ] ,
624
611
event : PromptEvent ,
625
612
) -> anyhow:: Result < ( ) > {
626
613
if event != PromptEvent :: Validate {
627
614
return Ok ( ( ) ) ;
628
615
}
629
-
630
- write_all_impl ( cx, args , event , true , true )
616
+ let _ = write_all_impl ( cx , true , true ) ;
617
+ quit_all_impl ( cx. editor , true )
631
618
}
632
619
633
620
fn quit_all_impl ( editor : & mut Editor , force : bool ) -> anyhow:: Result < ( ) > {
0 commit comments